Struct enumeration::Variant
source · 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: PartialEq + Debug> PartialEq<Variant<T>> for Variant<T>
impl<T: PartialEq + Debug> PartialEq<Variant<T>> for Variant<T>
source§impl<T: PartialOrd + Debug> PartialOrd<Variant<T>> for Variant<T>
impl<T: PartialOrd + Debug> PartialOrd<Variant<T>> for Variant<T>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moreimpl<T: Copy + Debug> Copy for Variant<T>
impl<T: Eq + Debug> Eq for Variant<T>
impl<T: Debug> StructuralEq for Variant<T>
impl<T: Debug> StructuralPartialEq for Variant<T>
Auto Trait Implementations§
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