Derive Macro strum_macros::ToString

source ·
#[derive(ToString)]
{
    // Attributes available to this derive:
    #[strum]
}
👎Deprecated since 0.22.0: please use #[derive(Display)] instead. See issue https://github.com/Peternator7/strum/issues/132
Expand description

implements std::string::ToString on en 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());