Typemarker
Procedural macro for easily creating multiple linked marker types, useful for the typestate pattern.
Examples
By default, typemarker adds both a trait and a dynamic value for the marker enum called "Trait" and "Dynamic" respectively.
use PhantomData;
use typemarker;
;
let light = ;
assert!;
let light = light.turn_green;
assert!;
Both the trait and the dynamic value can be disabled using no_value and no_trait respectively.
use PhantomData;
use typemarker;
// Compile error, LightColor::Trait does not exist on no_trait.
// struct TrafficLight<Color: LightColor::Trait>(PhantomData<Color>);
;
// Compile error, dynamic doesn't exist on no_value.
// impl<Color: LightColor::Trait> TrafficLight<Color> {
// fn can_go(&self) -> bool {
// Color::dynamic() == LightColor::Dynamic::Green
// }
// }
let light = ;
light.turn_green;
They can also be renamed using trait_name = ... and value_name = ...:
use PhantomData;
use typemarker;
;
let light = ;
assert!;
let light = light.turn_green;
assert!;