Derive Macro strum::ToString

source ·
#[derive(ToString)]
{
    // Attributes available to this derive:
    #[strum]
}
Available on crate feature derive only.
Expand description

implements std::string::ToString on an enum

// You need to bring the ToString trait into scope to use it
use std::string::ToString;
use strum_macros;

#[derive(strum_macros::ToString, Debug)]
enum Color {
    #[strum(serialize = "redred")]
    Red,
    Green {
        range: usize,
    },
    Blue(usize),
    Yellow,
}

// uses the serialize string for Display
let red = Color::Red;
assert_eq!(String::from("redred"), red.to_string());
// by default the variants Name
let yellow = Color::Yellow;
assert_eq!(String::from("Yellow"), yellow.to_string());