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
sourceimpl<T: Debug> Variant<T>
impl<T: Debug> Variant<T>
sourcepub fn new<E: Enumeration>(e: E) -> Variant<E::Index>
pub fn new<E: Enumeration>(e: E) -> Variant<E::Index>
Construct Variant with Enumeration
sourcepub fn cast<E: Enumeration<Index = T>>(self) -> Result<E, CastError<E>>
pub fn cast<E: Enumeration<Index = T>>(self) -> Result<E, CastError<E>>
Try casting to the given generic parameter
Trait Implementations
sourceimpl<T: Enumeration> From<T> for Variant<T::Index>
impl<T: Enumeration> From<T> for Variant<T::Index>
sourceimpl<T: Ord + Debug> Ord for Variant<T>
impl<T: Ord + Debug> Ord for Variant<T>
sourceimpl<T: PartialOrd + Debug> PartialOrd<Variant<T>> for Variant<T>
impl<T: PartialOrd + Debug> PartialOrd<Variant<T>> for Variant<T>
sourcefn partial_cmp(&self, other: &Variant<T>) -> Option<Ordering>
fn partial_cmp(&self, other: &Variant<T>) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn 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 more
impl<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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more