Trait vesta::CaseExt [−][src]
An extension trait providing methods analogous to those in Case
, but which take self
and
type parameters.
💡 Prefer using these to directly calling the methods in Case
.
Provided methods
unsafe fn case<const N: usize>(self) -> Self::Case where
Self: Case<N>,
[src]
Self: Case<N>,
If the value’s tag
is N
, return that case.
Safety
It is undefined behavior to call this function when self.tag()
would return
anything other than Some(n)
, where n = N
.
Examples
use vesta::{Match, CaseExt}; let option = Some("hello"); assert_eq!(option.tag(), Some(1)); let string = unsafe { option.case::<1>() }; assert_eq!(string, "hello");
fn try_case<const N: usize>(self) -> Result<Self::Case, Self> where
Self: Case<N>,
[src]
Self: Case<N>,
If the value’s tag
is N
, return that case; otherwise, return self
.
Examples
use vesta::CaseExt; let result = Some("hello").try_case::<1>(); assert_eq!(result, Ok("hello"));
fn uncase<T, const N: usize>(self) -> T where
T: Case<N, Case = Self>,
[src]
T: Case<N, Case = Self>,