Trait vesta::CaseExt[][src]

pub trait CaseExt: Sized {
    unsafe fn case<const N: usize>(self) -> Self::Case
    where
        Self: Case<N>
, { ... }
fn try_case<const N: usize>(self) -> Result<Self::Case, Self>
    where
        Self: Case<N>
, { ... }
fn uncase<T, const N: usize>(self) -> T
    where
        T: Case<N, Case = Self>
, { ... } }

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]

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]

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]

The inverse of case: inject this case back into the matched type.

This operation must not panic or otherwise fail.

Examples

use vesta::CaseExt;

let option: Option<_> = "hello".uncase::<_, 1>();
assert_eq!(option, Some("hello"));
Loading content...

Implementors

impl<T: Sized> CaseExt for T[src]

Loading content...