Macro enum_derive_2018::EnumInnerAsTrait
source · macro_rules! EnumInnerAsTrait { ($arg:tt $vis:vis enum $name:ident { $($body:tt)* }) => { ... }; }
Expand description
Derives a method for an unary enum returning a borrowed pointer to the inner value, cast to a trait object.
EnumInnerAsTrait!
accepts a single deriving form that specifies the name of the method to be derived,
whether the borrow should be mutable, and the trait of interest.
For example:
macro_attr! {
#[derive(EnumInnerAsTrait!(pub as_display -> &dyn std::fmt::Display))]
enum Value {
U32(u32),
U64(u64),
}
}
let s = format!("{}", Value::U64(42).as_display());
assert_eq!(&s[..], "42");