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

Round tripping "{{}}" doesn't work with Display + EnumString in 0.26 #361

Open
tiye opened this issue Jun 4, 2024 · 2 comments
Open

Round tripping "{{}}" doesn't work with Display + EnumString in 0.26 #361

tiye opened this issue Jun 4, 2024 · 2 comments

Comments

@tiye
Copy link

tiye commented Jun 4, 2024

upgraded from 0.25.2 to 0.26. My previous code broke. here are the cases I reproduced. any suggestion?

case 1

use strum_macros::{AsRefStr, EnumString};

#[derive(EnumString, strum_macros::Display, AsRefStr, Debug)]
enum A {
    #[strum(serialize = "{}")] // <--- this lie
    Bra,
    #[strum(serialize = "nor")]
    Nor,
}

fn main() {
    println!("{}", A::Bra);

    // parse
    let a = "{}".parse::<A>();
    println!("{:?}", a);
}
error: 1 positional argument in format string, but no arguments were given
 --> src/main.rs:5:26
  |
5 |     #[strum(serialize = "{}")]
  |                          ^^

error: could not compile `strum-demo` (bin "strum-demo") due to 1 previous error

case 2

use strum_macros::{AsRefStr, EnumString};

#[derive(EnumString, strum_macros::Display, AsRefStr, Debug)]
enum A {
    #[strum(serialize = "{{}}")] // <--- this line
    Bra,
    #[strum(serialize = "nor")]
    Nor,
}

fn main() {
    println!("{}", A::Bra);

    // parse
    let a = "{}".parse::<A>();
    println!("{:?}", a);
}
{}
Err(VariantNotFound)

case 3

use strum_macros::{AsRefStr, EnumString};

#[derive(EnumString, strum_macros::Display, AsRefStr, Debug)]
enum A {
    #[strum(serialize = "{{}}")] // <--- this line
    Bra,
    #[strum(serialize = "nor")]
    Nor,
}

fn main() {
    println!("{}", A::Bra);

    // parse
    let a = "{{}}".parse::<A>();
    println!("{:?}", a);
}
{}
Ok(Bra)
@martin-g
Copy link

martin-g commented Jun 4, 2024

Looks related to #359

@Peternator7 Peternator7 changed the title strange behavior using {} in serialize macro Round tripping "{{}}" doesn't work with Display + EnumString Jun 5, 2024
@Peternator7 Peternator7 changed the title Round tripping "{{}}" doesn't work with Display + EnumString Round tripping "{{}}" doesn't work with Display + EnumString in 0.26 Jun 5, 2024
@Peternator7
Copy link
Owner

Hey @tiye, sorry for the break here. There was a breaking change upgrading to 0.26 around format strings, but it should work correctly with escaped curly-braces so that's a bug. I'll work on fixing this, but in the meantime, the best solution is going to be staying on 0.25

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants