serde-rs / serde

Serialization framework for Rust
https://serde.rs/
Apache License 2.0
9.06k stars 767 forks source link

[toml] Rename attribute includes double quotes when resulting name contains dots #2717

Open Gigas002 opened 6 months ago

Gigas002 commented 6 months ago

Code sample:

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Config {
    pub keybindings: Option<String>,
    #[serde(rename = "clipboard")]
    pub clipboard: Option<String>,
    #[serde(rename = "screenshot.filesystem")]
    pub filesystem: Option<String>,
}

impl Default for Config {
    fn default() -> Self {
        Config {
            keybindings: Some("hello".to_string()),
            clipboard: Some("toml".to_string()),
            filesystem: Some("serde".to_string()),
        }
    }
}

fn main() {
    let config = Config::default();
    let serialized = toml::to_string_pretty(&config).unwrap();
    let mut file = File::create("output.toml").unwrap();
    file.write_all(serialized.as_bytes()).unwrap();
}

This code produces this output:

keybindings = "hello"
clipboard = "toml"
"screenshot.filesystem" = "serde"

Not sure if it's serde or toml crate's problem, though...