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

Allow serialization of unit variant as string #43

Open
ngoquang2708 opened this issue Jul 12, 2024 · 0 comments
Open

Allow serialization of unit variant as string #43

ngoquang2708 opened this issue Jul 12, 2024 · 0 comments

Comments

@ngoquang2708
Copy link

Currently I can deserialize HashMap with key as an enum as example bellow:

#[derive(PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
enum Extension {
    #[serde(rename = "ut_metadata")]
    Metadata,
}
serde_bencode::from_str::<std::collections::HashMap<Extension, u8>>("d11:ut_metadatai1ee").unwrap();

But I cannot serialize a HashMap to a string:

serde_bencode::to_string(&std::collections::HashMap::from([(Extension::Metadata, 1)])).unwrap();

If I modifiy the serialize_newtype_struct() to allow serialize unit variant as a string the above code work. I don't know if it will break anything else so please consider.

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