Struct enumeration::VariantWith
source · pub struct VariantWith<T: Debug, U: 'static> { /* private fields */ }
Expand description
Provides runtime specialized representation of Enumeration with specified Enumeration::AssociatedValueType. More details in Variant.
It’s basically Variant but with specified on what it’s Enumeration::AssociatedValueType must be.
Examples
ⓘ
enumerate!(Foo(u8; i32)
Bar = 111
Baz = 333
);
enumerate!(Color(u8; &'static str)
Red = "#FF0000"
Blue = "#0000FF"
Yellow = "#FFFF00"
Cyan = "#00FFFF"
);
let mut vec = vec![Color::Red.into(), Color::Blue.into()];
assert_eq!(vec[0].value(), "#FF0000");
vec.push(Foo::Bar.into()); // compile error
Implementations§
source§impl<T: Debug, U: 'static> VariantWith<T, U>
impl<T: Debug, U: 'static> VariantWith<T, U>
sourcepub fn new<E: Enumeration>(
e: E
) -> VariantWith<E::Index, E::AssociatedValueType>
pub fn new<E: Enumeration>( e: E ) -> VariantWith<E::Index, E::AssociatedValueType>
Constructs VariantWith with Enumeration
sourcepub fn value(self) -> &'static U
pub fn value(self) -> &'static U
Returns the associated constant value without casting.
sourcepub fn cast<E: Enumeration<Index = T, AssociatedValueType = U>>(
self
) -> Result<E, CastError<E>>
pub fn cast<E: Enumeration<Index = T, AssociatedValueType = U>>( self ) -> Result<E, CastError<E>>
Try casting to the given generic parameter
Trait Implementations§
source§impl<T: Clone + Debug, U: Clone + 'static> Clone for VariantWith<T, U>
impl<T: Clone + Debug, U: Clone + 'static> Clone for VariantWith<T, U>
source§fn clone(&self) -> VariantWith<T, U>
fn clone(&self) -> VariantWith<T, U>
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl<T: Enumeration> From<T> for VariantWith<T::Index, T::AssociatedValueType>
impl<T: Enumeration> From<T> for VariantWith<T::Index, T::AssociatedValueType>
source§impl<T: Ord + Debug, U: Ord + 'static> Ord for VariantWith<T, U>
impl<T: Ord + Debug, U: Ord + 'static> Ord for VariantWith<T, U>
source§fn cmp(&self, other: &VariantWith<T, U>) -> Ordering
fn cmp(&self, other: &VariantWith<T, U>) -> Ordering
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, U: PartialEq + 'static> PartialEq<VariantWith<T, U>> for VariantWith<T, U>
impl<T: PartialEq + Debug, U: PartialEq + 'static> PartialEq<VariantWith<T, U>> for VariantWith<T, U>
source§fn eq(&self, other: &VariantWith<T, U>) -> bool
fn eq(&self, other: &VariantWith<T, U>) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl<T: PartialOrd + Debug, U: PartialOrd + 'static> PartialOrd<VariantWith<T, U>> for VariantWith<T, U>
impl<T: PartialOrd + Debug, U: PartialOrd + 'static> PartialOrd<VariantWith<T, U>> for VariantWith<T, U>
source§fn partial_cmp(&self, other: &VariantWith<T, U>) -> Option<Ordering>
fn partial_cmp(&self, other: &VariantWith<T, U>) -> Option<Ordering>
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, U: Copy + 'static> Copy for VariantWith<T, U>
impl<T: Eq + Debug, U: Eq + 'static> Eq for VariantWith<T, U>
impl<T: Debug, U: 'static> StructuralEq for VariantWith<T, U>
impl<T: Debug, U: 'static> StructuralPartialEq for VariantWith<T, U>
Auto Trait Implementations§
impl<T, U> RefUnwindSafe for VariantWith<T, U>where T: RefUnwindSafe, U: RefUnwindSafe,
impl<T, U> Send for VariantWith<T, U>where T: Send, U: Sync,
impl<T, U> Sync for VariantWith<T, U>where T: Sync, U: Sync,
impl<T, U> Unpin for VariantWith<T, U>where T: Unpin,
impl<T, U> UnwindSafe for VariantWith<T, U>where T: UnwindSafe, U: RefUnwindSafe,
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