Struct Union

Source
pub struct Union<P1: Pattern, P2: Pattern>(pub P1, pub P2);
Expand description

A pattern that matches either of the 2 patterns in a short-circuiting manner, with self tried first. May be created by Pattern::or for convenience.

§Note

If you want to match either of N chars, use an array of them as a pattern instead, as this struct has a general impl that may miss optimisations applicable to the case of [char; N] being the pattern. However, unlike the array pattern, the combination of patterns using this struct is not commutative, since the second pattern is only tried if the former has not been found in the input.

Tuple Fields§

§0: P1§1: P2

Trait Implementations§

Source§

impl<P1: Clone + Pattern, P2: Clone + Pattern> Clone for Union<P1, P2>

Source§

fn clone(&self) -> Union<P1, P2>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<P1: Debug + Pattern, P2: Debug + Pattern> Debug for Union<P1, P2>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<P1: Pattern, P2: Pattern> Pattern for Union<P1, P2>

Source§

fn immediate_match<I: Input>(&self, input: I) -> Result<(I, I), I>

The return values are (rest of the input, matched fragment at the beginning). Read more
Source§

fn trailing_match<I: Input>(&self, input: I) -> Result<(I, I), I>

Like Pattern::immediate_match, but matches at the end of input. The return values are (the input before the match, the match) Read more
Source§

fn first_match<I: Input>(&self, input: I) -> Result<(I, (I, I)), I>

The return values are (the match + rest of the input, (string before the match, the match)). Read more
Source§

fn first_match_ex<I: Input>(&self, input: I) -> Result<(I, (I, I)), I>

Like Pattern::first_match, but the match is excluded from the rest of the input. Read more
Source§

fn immediate_matches<I: Input>(&self, input: I) -> (I, I)

The return values are (rest of the input, contiguous matched fragments from the beginning). Read more
Source§

fn immediate_matches_counted<I: Input>(&self, input: I) -> (I, (I, usize))

Like Pattern::immediate_matches, but also counts the number of matches. Read more
Source§

fn trailing_matches_counted<I: Input>(&self, input: I) -> (I, usize)

Like Pattern::immediate_matches_counted, but matches at the end of input, and doesn’t return the matched fragment of the input. Read more
Source§

fn by_ref(&self) -> Ref<'_, Self>

Get the pattern by reference to avoid moving it, which will happen in generic code Read more
Source§

fn or<Other: Pattern>(self, other: Other) -> Union<Self, Other>
where Self: Sized,

Combine self and another pattern into a pattern that matches either of them in a short-circuiting manner, with self tried first. Read more
Source§

fn not_escaped_by<Prefix: Pattern>( self, prefix: Prefix, ) -> NotEscaped<Prefix, Self>
where Self: Sized,

Create a pattern that’ll match self only if it’s not escaped (immediately preceded) by the provided pattern.
Source§

fn not_enclosed_by<Enclosure: Pattern>( self, enc: Enclosure, ) -> NotEnclosed<Enclosure, Self>
where Self: Sized,

Create a pattern that’ll match self only if it’s not enclosed (preceded & superceded) by the provided pattern.
Source§

impl<P1: Copy + Pattern, P2: Copy + Pattern> Copy for Union<P1, P2>

Auto Trait Implementations§

§

impl<P1, P2> Freeze for Union<P1, P2>
where P1: Freeze, P2: Freeze,

§

impl<P1, P2> RefUnwindSafe for Union<P1, P2>

§

impl<P1, P2> Send for Union<P1, P2>
where P1: Send, P2: Send,

§

impl<P1, P2> Sync for Union<P1, P2>
where P1: Sync, P2: Sync,

§

impl<P1, P2> Unpin for Union<P1, P2>
where P1: Unpin, P2: Unpin,

§

impl<P1, P2> UnwindSafe for Union<P1, P2>
where P1: UnwindSafe, P2: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.