Trait vesta::Match [−][src]
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.
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());
Implementations on Foreign Types
impl Match for Infallible
[src]
impl<T> Match for Option<T>
[src]
impl<T, E> Match for Result<T, E>
[src]
impl<'a, B: ?Sized> Match for Cow<'a, B> where
B: 'a + ToOwned,
[src]
B: 'a + ToOwned,
impl Match for VarError
[src]
impl Match for SeekFrom
[src]
impl<T> Match for Bound<T>
[src]
impl Match for IpAddr
[src]
impl Match for SocketAddr
[src]
impl Match for Shutdown
[src]
impl<T> Match for TryLockError<T>
[src]
impl Match for TryRecvError
[src]
impl Match for RecvTimeoutError
[src]
impl<T> Match for TrySendError<T>
[src]
impl Match for FpCategory
[src]
impl Match for Alignment
[src]
impl<'a> Match for Prefix<'a>
[src]
impl<'a> Match for Component<'a>
[src]
impl Match for ErrorKind
[src]
impl Match for Ordering
[src]
impl Match for Ordering
[src]
impl<'a, K, V> Match for Entry<'a, K, V> where
K: 'a,
V: 'a,
[src]
K: 'a,
V: 'a,
impl<'a, K, V> Match for Entry<'a, K, V> where
K: 'a,
V: 'a,
[src]
Loading content...K: 'a,
V: 'a,