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

Serialization of keys varies depending on whether the feature flag "parse" is enabled #708

Open
Zireael-N opened this issue Mar 30, 2024 · 0 comments

Comments

@Zireael-N
Copy link

If this feature flag is disabled, then all keys are double quoted, otherwise they aren't (unless necessary).

Code to reproduce:

use serde::Serialize;
use std::collections::BTreeMap;
 
#[derive(Serialize)]
struct Example {
    name: String,
    extra: BTreeMap<String, u8>,
}
 
fn main() {
    let example = Example {
        name: "Example".into(),
        extra: (0..3)
            .map(|i| (format!("{}", (b'a' + i) as char), i))
            .collect(),
    };
    println!("{}", toml::to_string_pretty(&example).unwrap());
}

Output with default-features = false, features = ["display"]:

"name" = "Example"

["extra"]
"a" = 0
"b" = 1
"c" = 2

Output with default features:

name = "Example"

[extra]
a = 0
b = 1
c = 2
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

1 participant