pub enum Either<A, B, C = Invalid, D = Invalid> {
First(A),
Second(B),
Third(C),
Fourth(D),
}Expand description
Disjunctive A or B or optional C or D tried in that order.
When C and D are not used, they are set to Invalid.
Variants§
First(A)
The first alternative
Second(B)
The second alternative
Third(C)
The third alternative
Fourth(D)
The fourth alternative
Implementations§
Source§impl<A, B, C, D> Either<A, B, C, D>where
C: 'static,
D: 'static,
impl<A, B, C, D> Either<A, B, C, D>where
C: 'static,
D: 'static,
Sourcepub fn fold2<R, FA, FB>(self, first_fn: FA, second_fn: FB) -> R
pub fn fold2<R, FA, FB>(self, first_fn: FA, second_fn: FB) -> R
Deconstructs an Either with 2 alternatives and produces a common result type, by
applying one of the two functions depending on the alternative.
§Panics
When the variant is Either::Third or Either::Fourth
§Example
let either = Either::<LiteralInteger, Ident>::First(LiteralInteger::new(42));
let result: String = either.fold2(
|a| a.tokens_to_string(),
|b| b.tokens_to_string(),
);
assert_eq!(result, "42");Sourcepub fn fold3<R, FA, FB, FC>(
self,
first_fn: FA,
second_fn: FB,
third_fn: FC,
) -> R
pub fn fold3<R, FA, FB, FC>( self, first_fn: FA, second_fn: FB, third_fn: FC, ) -> R
Deconstructs an Either with 3 alternatives and produces a common result type, by
applying one of the three functions depending on the alternative.
§Panics
When the variant is Either::Fourth
Sourcepub fn fold4<R, FA, FB, FC, FD>(
self,
first_fn: FA,
second_fn: FB,
third_fn: FC,
fourth_fn: FD,
) -> R
pub fn fold4<R, FA, FB, FC, FD>( self, first_fn: FA, second_fn: FB, third_fn: FC, fourth_fn: FD, ) -> R
Deconstructs an Either with 4 alternatives and produces a common result type, by
applying one of the provided functions.
Sourcepub fn into2<T>(self) -> T
pub fn into2<T>(self) -> T
Deconstructs an Either with 2 alternatives and produces a common result type for
types that implement Into<T>.
§Panics
When more then two alternatives are used.
§Example
let either = Either::<LiteralInteger, Ident>::First(LiteralInteger::new(42));
let tt: TokenTree = either.into2();
assert_tokens_eq!(tt, "42");Trait Implementations§
Source§impl<A, B, C, D> Parser for Either<A, B, C, D>
impl<A, B, C, D> Parser for Either<A, B, C, D>
Source§fn parser(tokens: &mut TokenIter) -> Result<Either<A, B, C, D>, Error>
fn parser(tokens: &mut TokenIter) -> Result<Either<A, B, C, D>, Error>
tokens
iterator directly. It should not be called from user code except for implementing
parsers itself and then only when the rules below are followed. Read moreSource§impl<A, B, C, D> ToTokens for Either<A, B, C, D>
impl<A, B, C, D> ToTokens for Either<A, B, C, D>
Source§fn to_tokens(&self, tokens: &mut TokenStream)
fn to_tokens(&self, tokens: &mut TokenStream)
Source§fn into_token_iter(self) -> TokenIter ⓘwhere
Self: Sized,
fn into_token_iter(self) -> TokenIter ⓘwhere
Self: Sized,
self into a TokenIter object.Source§fn to_token_stream(&self) -> TokenStream
fn to_token_stream(&self) -> TokenStream
&self into a TokenStream object.Source§fn into_token_stream(self) -> TokenStreamwhere
Self: Sized,
fn into_token_stream(self) -> TokenStreamwhere
Self: Sized,
self into a TokenStream object.Auto Trait Implementations§
impl<A, B, C, D> Freeze for Either<A, B, C, D>
impl<A, B, C, D> RefUnwindSafe for Either<A, B, C, D>
impl<A, B, C, D> Send for Either<A, B, C, D>
impl<A, B, C, D> Sync for Either<A, B, C, D>
impl<A, B, C, D> Unpin for Either<A, B, C, D>
impl<A, B, C, D> UnwindSafe for Either<A, B, C, D>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> DynamicTokens for T
impl<T> DynamicTokens for T
Source§impl<T> Parse for Twhere
T: Parser,
impl<T> Parse for Twhere
T: Parser,
Source§fn parse(tokens: &mut TokenIter) -> Result<Self, Error>
fn parse(tokens: &mut TokenIter) -> Result<Self, Error>
parser() within a
transaction. Commits changes on success and returns the parsed value. Read more