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

strum(serialize_all vs serde(rename_all #278

Open
alekspickle opened this issue Jun 26, 2023 · 1 comment
Open

strum(serialize_all vs serde(rename_all #278

alekspickle opened this issue Jun 26, 2023 · 1 comment

Comments

@alekspickle
Copy link

alekspickle commented Jun 26, 2023

Let's say we have a simple strum enfused enum and we want both display and serialization be lowercase.


#[derive(Serialize, Deserialize, Display, Clone, Debug, Default, PartialEq, EnumString)]
//#[serde(rename_all = "lowercase")]
#[strum(serialize_all = "lowercase")]
pub enum Status {
    Online,
    Medium,
    #[default]
    Offline,
}
...

#[test]
fn enum_serialize() {
    let status = Status::Offline;
    assert_eq!("offline", status.to_string());
}

Strum version will lead for this to be lowecase whereas serde rename_all will not.
With serialization it's right the opposite.

What is the gotcha here?

Edit: I guess @kraktus is right, but it feels wrong setting duplicating logic for both serialization and code usage.

anything we can do here? strum is a cool minimalistic part of ecosystem and everyone will benefit if it became more convenient

@kraktus
Copy link
Contributor

kraktus commented Jul 26, 2023

Isn't the catch just that strum only apply to the ToString trait while serve only applies to the Serialize one?

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

2 participants