Crates.io | labelled-enum |
lib.rs | labelled-enum |
version | 0.1.1 |
source | src |
created_at | 2022-03-26 09:50:29.63102 |
updated_at | 2022-03-26 10:04:45.761167 |
description | Converting an enum to/from String |
homepage | https://github.com/myuon/labelled-enum#readme |
repository | https://github.com/myuon/labelled-enum |
max_upload_size | |
id | 556627 |
size | 6,027 |
Converting an enum to/from String.
Derives ToString, FromStr impl:
#[derive(ToString, FromStr)]
enum Test {
Foo,
Bar,
}
assert_eq!(Test::Foo.to_string(), "Foo");
assert_eq!(Test::from_str("Foo").unwrap(), Test::Foo);
You can specify snake_case using attribute:
#[derive(ToString, FromStr)]
#[label(rename_all = "snake_case")]
enum Test {
SnakeCase,
}
labelled-enum provides serde_plugin
feature to work with serde Serializer/Deserializer:
// install labelled-enum with --features serde_plugin
#[derive(Serialize, Deserialize)]
struct Wrapper {
#[serde(with = "labelled_enum::serde_plugin")]
test_snake_case: TestSnakeCase,
}