pub enum Token<T, S> {
Known(T),
Unknown(S),
}Expand description
A token which may be a statically known value of type T or else an unknown value of type
S.
The principal use of this type is to allow finite enums to be extended with arbitrary values, most commonly some unknown string which is permissible but statically unknowable.
Variants§
Implementations§
Source§impl<T, S> Token<T, S>
impl<T, S> Token<T, S>
Sourcepub fn try_from_str<'a>(
s: &'a str,
) -> Result<Self, <&'a str as TryInto<S>>::Error>
pub fn try_from_str<'a>( s: &'a str, ) -> Result<Self, <&'a str as TryInto<S>>::Error>
Like FromStr, but uses a fallible conversion for the unknown variant.
Sourcepub fn map_unknown<U>(self, f: impl FnOnce(S) -> U) -> Token<T, U>
pub fn map_unknown<U>(self, f: impl FnOnce(S) -> U) -> Token<T, U>
Maps the unknown value of a Token, leaving known values unchanged.
Trait Implementations§
Source§impl<T: Ord, S: Ord> Ord for Token<T, S>
impl<T: Ord, S: Ord> Ord for Token<T, S>
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: PartialOrd, S: PartialOrd> PartialOrd for Token<T, S>
impl<T: PartialOrd, S: PartialOrd> PartialOrd for Token<T, S>
impl<T: Copy, S: Copy> Copy for Token<T, S>
impl<T: Eq, S: Eq> Eq for Token<T, S>
impl<T, S> StructuralPartialEq for Token<T, S>
Auto Trait Implementations§
impl<T, S> Freeze for Token<T, S>
impl<T, S> RefUnwindSafe for Token<T, S>where
T: RefUnwindSafe,
S: RefUnwindSafe,
impl<T, S> Send for Token<T, S>
impl<T, S> Sync for Token<T, S>
impl<T, S> Unpin for Token<T, S>
impl<T, S> UnsafeUnpin for Token<T, S>where
T: UnsafeUnpin,
S: UnsafeUnpin,
impl<T, S> UnwindSafe for Token<T, S>where
T: UnwindSafe,
S: UnwindSafe,
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