Module enum_debug::derive

source ·
Expand description

The EnumDebug-trait is most powerful when combined with the EnumDebug-derive macro. This macro is only available when the derive- feature is used.

To use it, simply derive EnumDebug:

use enum_debug::EnumDebug;

#[derive(EnumDebug)]
enum Jedi {
    ObiWanKenobi,
    AnakinSkywalker,
    MaceWindu,
    MasterYoda,
}

assert_eq!(format!("{}", Jedi::ObiWanKenobi.variant()), "ObiWanKenobi");
assert_eq!(format!("{:?}", Jedi::AnakinSkywalker.variant()), "Jedi::AnakinSkywalker");
assert_eq!(Jedi::MaceWindu.variant().to_string(), "MaceWindu");

You can also give it a different type name:

use enum_debug::EnumDebug;

#[derive(EnumDebug)]
#[enum_debug(name = "ForceWielder")]
enum Jedi {
    ObiWanKenobi,
    AnakinSkywalker,
    MaceWindu,
    MasterYoda,
}

assert_eq!(&format!("{:?}", Jedi::ObiWanKenobi.variant()), "ForceWielder::ObiWanKenobi");

Or use the full path name as generated by Rust:

use enum_debug::EnumDebug;

#[derive(EnumDebug)]
#[enum_debug(path)]
enum Jedi {
    ObiWanKenobi,
    AnakinSkywalker,
    MaceWindu,
    MasterYoda,
}

assert_eq!(
    &format!("{:?}", Jedi::ObiWanKenobi.variant()),
    "rust_out::main::_doctest_main_src_lib_rs_152_0::Jedi::ObiWanKenobi"
);

Derive Macros§

  • Does the derivation for the EnumDebug.