mirror of
https://github.com/danog/strum.git
synced 2024-12-03 18:07:52 +01:00
1c00f6cfa5
* Run rustfmt over repository. * Bump `syn` to 0.15 * Implemented ability to `serialize_all` using cases from `heck`. Issue #21 * Use `path` and `version` in dependency specifications. Issue #21 * Updated documentation. Issue #21 * Added `CHANGELOG.md`. * Also convert case when deriving `Display`. Issue #21 * Added `EnumDiscriminants` derive. Issue #33 * Added the ability to rename derived `EnumDiscriminants`. Issue #33 * Updated `README.md` and lib.rs docs. Issue #33 * Updated `CHANGELOG.md`. Issue #33 * WIP: refactoring to allow attributes on discriminants enum. * Use single `strum_discriminants` top level attribute. Issue #33 * Allow multiple declarations of `strum_discriminants` attribute. Issue #33 * Pass through all other attributes to discriminant enum. Issue #33 * Add `impl From<MyEnum> for MyEnumDiscriminants`. Issue #33 * Add `impl<'_enum> From<&'_enum MyEnum> for MyEnumDiscriminants`. Issue #33 * Added complex case test for `From` derivation. Issue #33 * Added docs to some helper functions. * Added docs about `From` impls. Issue #33
35 lines
682 B
Rust
35 lines
682 B
Rust
#[macro_use]
|
|
extern crate strum_macros;
|
|
|
|
#[derive(Debug, Eq, PartialEq, AsRefStr)]
|
|
enum Color {
|
|
#[strum(to_string = "RedRed")]
|
|
Red,
|
|
#[strum(serialize = "b", to_string = "blue")]
|
|
Blue { hue: usize },
|
|
#[strum(serialize = "y", serialize = "yellow")]
|
|
Yellow,
|
|
#[strum(default = "true")]
|
|
Green(String),
|
|
}
|
|
|
|
#[test]
|
|
fn as_red_str() {
|
|
assert_eq!("RedRed", (Color::Red).as_ref());
|
|
}
|
|
|
|
#[test]
|
|
fn as_blue_str() {
|
|
assert_eq!("blue", (Color::Blue { hue: 0 }).as_ref());
|
|
}
|
|
|
|
#[test]
|
|
fn as_yellow_str() {
|
|
assert_eq!("yellow", (Color::Yellow).as_ref());
|
|
}
|
|
|
|
#[test]
|
|
fn as_green_str() {
|
|
assert_eq!("Green", (Color::Green(String::default())).as_ref());
|
|
}
|