pub struct Variant<T: Debug> { /* private fields */ }
Expand description
Provides runtime specialized representation of Enumeration.
To avoid using dyn
for mixing Enumeration, you can use Variant with a trade-off for having to try casting before using it.
§Examples
enumerate!(Foo(u8)
Bar
Baz
);
enumerate!(Color(u8)
Red
Green
Blue
);
let mut vec: Vec<Variant<u8>> = vec![Foo::Bar.into(), Color::Green.into(), Foo::Baz.into()]; // Variant::new(Foo::Bar) or Variant::from(Foo::Bar) works too
assert_eq!(vec[0].cast::<Foo>(), Ok(Foo::Bar));
assert!(vec[1].cast::<Foo>().is_err());
Implementations§
Trait Implementations§
Source§impl<T: Ord + Debug> Ord for Variant<T>
impl<T: Ord + Debug> Ord for Variant<T>
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl<T: PartialOrd + Debug> PartialOrd for Variant<T>
impl<T: PartialOrd + Debug> PartialOrd for Variant<T>
impl<T: Copy + Debug> Copy for Variant<T>
impl<T: Eq + Debug> Eq for Variant<T>
impl<T: Debug> StructuralPartialEq for Variant<T>
Auto Trait Implementations§
impl<T> Freeze for Variant<T>where
T: Freeze,
impl<T> RefUnwindSafe for Variant<T>where
T: RefUnwindSafe,
impl<T> Send for Variant<T>where
T: Send,
impl<T> Sync for Variant<T>where
T: Sync,
impl<T> Unpin for Variant<T>where
T: Unpin,
impl<T> UnwindSafe for Variant<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more