Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BotCommands can't derive enum variant where field is a custom struct #1031

Open
nomoreqwerty opened this issue Mar 20, 2024 · 0 comments
Open
Labels
A-macros Area: macros K-bug Kind: bug

Comments

@nomoreqwerty
Copy link

I tried this code:

use teloxide::macros::BotCommands;
use std::str::FromStr;
use serde_derive::*;

#[derive(Default, Debug, PartialEq, Clone, Copy, Serialize, Deserialize)]
pub struct UserId(pub u64);

impl FromStr for UserId {
    type Err = std::num::ParseIntError;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(UserId(s.parse()?))
    }
}

#[derive(Clone, PartialEq, BotCommands)]
#[command(rename_rule = "lowercase", parse_with = "split")]
pub enum AdministratorCommand {
    GiveStrike {
        member_id: UserId,
    }
}

fn main() {
    println!("omg! what happened?");
}

Instead of success building i get:

error[E0308]: mismatched types
  --> src\main.rs:16:28
   |
16 | #[derive(Clone, PartialEq, BotCommands)]
   |                            ^^^^^^^^^^^ expected `UserId`, found `u64`
   |
   = note: this error originates in the derive macro `BotCommands` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0308`.
error: could not compile `teloxide_report` (bin "teloxide_report") due to 1 previous error

-Z macro-backtrace doesn't work:

C:\Users\whoami\code\rust\sandbox\teloxide_report>cargo b -Z macro-backtrace
error: unknown `-Z` flag specified: macro-backtrace

For available unstable features, see https://doc.rust-lang.org/nightly/cargo/reference/unstable.html
If you intended to use an unstable rustc feature, try setting `RUSTFLAGS="-Zmacro-backtrace"`

Meta

  • teloxide = { version = "0.12.2", features = ["macros"] }
  • serde_derive = "1.0.197"
  • serde = "1.0.197"
  • host: nightly-x86_64-pc-windows-msvc (has updated to the last version)
@nomoreqwerty nomoreqwerty added the K-bug Kind: bug label Mar 20, 2024
@WaffleLapkin WaffleLapkin added the A-macros Area: macros label Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros Area: macros K-bug Kind: bug
Projects
None yet
Development

No branches or pull requests

2 participants