Trait vesta::Match[][src]

pub unsafe trait Match: Sized {
    type Range: Range;
    fn tag(&self) -> Option<usize>;
}

A type which is Match can be pattern-matched using the case! macro and the methods of CaseExt/Case.

In order for a type to be matched, it must implement Match, as well as Case for each distinct case it can be matched against.

Associated Types

type Range: Range[src]

The range of tag for this type: either Nonexhaustive, or Exhaustive<N> for some N.

No other types are permissible for this associated type; it is constrained by the sealed Range trait, which is only implemented for these two options.

Safety

If the Range is Exhaustive<N>, then tag must never return None. For all Some(m) it returns, m must be strictly less than N. Undefined behavior may result if this guarantee is violated.

Loading content...

Required methods

fn tag(&self) -> Option<usize>[src]

The tag of this value.

Safety

If this function returns Some(n), this is a guarantee that it is safe to call case for this value at the type level tag N = n. It is undefined behavior for this function to return Some(n) if <Self as Case<N>>::case(self) would be unsafe.

If the Range is Exhaustive<N>, then this function must never return None. For all Some(m) it returns, m must be strictly less than N. Undefined behavior may result if this guarantee is violated.

Only if the Range is Nonexhaustive is it safe for this function to return None. Returning None will cause all pattern matches on this value to take the default case.

This function should always return the same result. In general, it is impossible to safely implement Match for types with interior mutability, unless that interior mutability has no ability to change the tag. When pattern-matching occurs, there is no guarantee that self.tag() is checked and self.case() subsequently called (if applicable) in a single atomic action, which may lead to undefined behavior if the tag changes between these two moments.

Examples

use vesta::Match;

assert_eq!(Some(0), None::<bool>.tag());
assert_eq!(Some(1), Some(true).tag());
Loading content...

Implementations on Foreign Types

impl Match for Infallible[src]

type Range = Exhaustive<0usize>

impl<T> Match for Option<T>[src]

type Range = Exhaustive<2usize>

impl<T, E> Match for Result<T, E>[src]

type Range = Exhaustive<2usize>

impl<'a, B: ?Sized> Match for Cow<'a, B> where
    B: 'a + ToOwned
[src]

type Range = Exhaustive<2usize>

impl Match for VarError[src]

type Range = Exhaustive<2usize>

impl Match for SeekFrom[src]

type Range = Exhaustive<3usize>

impl<T> Match for Bound<T>[src]

type Range = Exhaustive<3usize>

impl Match for IpAddr[src]

type Range = Exhaustive<2usize>

impl Match for SocketAddr[src]

type Range = Exhaustive<2usize>

impl Match for Shutdown[src]

type Range = Exhaustive<3usize>

impl<T> Match for TryLockError<T>[src]

type Range = Exhaustive<2usize>

impl Match for TryRecvError[src]

type Range = Exhaustive<2usize>

impl Match for RecvTimeoutError[src]

type Range = Exhaustive<2usize>

impl<T> Match for TrySendError<T>[src]

type Range = Exhaustive<2usize>

impl Match for FpCategory[src]

type Range = Exhaustive<5usize>

impl Match for Alignment[src]

type Range = Exhaustive<3usize>

impl<'a> Match for Prefix<'a>[src]

type Range = Exhaustive<6usize>

impl<'a> Match for Component<'a>[src]

type Range = Exhaustive<5usize>

impl Match for ErrorKind[src]

impl Match for Ordering[src]

type Range = Exhaustive<3usize>

impl Match for Ordering[src]

impl<'a, K, V> Match for Entry<'a, K, V> where
    K: 'a,
    V: 'a, 
[src]

type Range = Exhaustive<2usize>

impl<'a, K, V> Match for Entry<'a, K, V> where
    K: 'a,
    V: 'a, 
[src]

type Range = Exhaustive<2usize>

Loading content...

Implementors

Loading content...