Derive Macro enumcapsulate_macros::AsVariant
source · #[derive(AsVariant)]Expand description
Derive macro generating an impl of the trait AsVariant<T>.
It generates an impl for each of the enum’s
newtype variants, where Inner is the variant’s field type
and Outer is the enclosing enum’s type.
#[derive(Clone)]
struct Inner;
enum Outer {
Inner(Inner),
// ...
}
// The generated impls look something along these lines:
impl AsVariant<Inner> for Outer {
fn as_variant(&self) -> Option<Inner> {
match self {
Outer::Inner(inner) => Some(inner.clone()),
_ => None,
}
}
}
// ...