pub struct Chain<P1: Pattern, P2: Pattern>(pub P1, pub P2);Expand description
A pattern that matches P1 immediately followed by P2.
A match is only produced when both patterns match consecutively at
the same position: P1 at the current position and P2 right after it.
The combined match spans the entirety of both sub-matches.
§Note
For first_match / first_match_ex, every occurrence of P1 in the
input is tried in left-to-right order; the first one where P2
immediately follows is returned. Occurrences of P1 that are not
followed by P2 are skipped.
More conveniently created via Pattern::and.
§Example
use {
shrimple_parser::{
Pattern,
parser::{one, until_ex},
pattern::{ascii_digit, alphabetic, Chain},
},
core::convert::Infallible,
};
// Matches a digit immediately followed by an alphabetic character.
assert_eq!(
one::<_, Infallible>(ascii_digit.and(alphabetic))("3x rest"),
Ok((" rest", "3x")),
);
// Returns an error when the pattern is not at the start.
assert!(
one::<_, Infallible>(ascii_digit.and(alphabetic))("x3 rest")
.is_err()
);
// Finds the first '$' that is immediately followed by '{'.
assert_eq!(
until_ex::<_, Infallible>('$'.and('{'))("foo${bar}"),
Ok(("bar}", "foo")),
);Tuple Fields§
§0: P1§1: P2Trait Implementations§
impl<P1: Copy + Pattern, P2: Copy + Pattern> Copy for Chain<P1, P2>
Source§impl<P1: Pattern, P2: Pattern> Pattern for Chain<P1, P2>
impl<P1: Pattern, P2: Pattern> Pattern for Chain<P1, P2>
Source§fn immediate_match<I: Input>(&self, input: I) -> Result<(I, I), I>
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>
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 moreSource§fn first_match<I: Input>(&self, input: I) -> Result<(I, (I, I)), I>
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>
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 moreSource§fn immediate_matches<I: Input>(&self, input: I) -> (I, I)
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))
fn immediate_matches_counted<I: Input>(&self, input: I) -> (I, (I, usize))
Like
Pattern::immediate_matches, but also counts the number of matches. Read moreSource§fn trailing_matches_counted<I: Input>(&self, input: I) -> (I, usize)
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 moreSource§fn by_ref(&self) -> Ref<'_, Self>
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 and<Other: Pattern>(self, other: Other) -> Chain<Self, Other>where
Self: Sized,
fn and<Other: Pattern>(self, other: Other) -> Chain<Self, Other>where
Self: Sized,
Combine
self and another pattern into a pattern that matches both of them in a sequence,
with self before other Read moreSource§fn not_escaped_by<Prefix: Pattern>(
self,
prefix: Prefix,
) -> NotEscaped<Prefix, Self>where
Self: Sized,
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. Read moreSource§fn not_enclosed_by<Enclosure: Pattern>(
self,
enc: Enclosure,
) -> NotEnclosed<Enclosure, Self>where
Self: Sized,
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. Read moreAuto Trait Implementations§
impl<P1, P2> Freeze for Chain<P1, P2>
impl<P1, P2> RefUnwindSafe for Chain<P1, P2>where
P1: RefUnwindSafe,
P2: RefUnwindSafe,
impl<P1, P2> Send for Chain<P1, P2>
impl<P1, P2> Sync for Chain<P1, P2>
impl<P1, P2> Unpin for Chain<P1, P2>
impl<P1, P2> UnsafeUnpin for Chain<P1, P2>where
P1: UnsafeUnpin,
P2: UnsafeUnpin,
impl<P1, P2> UnwindSafe for Chain<P1, P2>where
P1: UnwindSafe,
P2: 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> IntoPattern for Twhere
T: Pattern,
impl<T> IntoPattern for Twhere
T: Pattern,
Source§fn into_pattern(self) -> <T as IntoPattern>::Pattern
fn into_pattern(self) -> <T as IntoPattern>::Pattern
Converts the value into a pattern.