pub struct Many<T: Pattern>(pub T);Expand description
A pattern that matches any number of contiguous occurrences of the inner pattern T,
including 0.
Because 0 occurrences is always a valid match, Many never fails: Pattern::immediate_match
and Pattern::trailing_match always return Ok, and Pattern::first_match /
Pattern::first_match_ex always match at the very start of the input (with a possibly
empty match).
More conveniently created via Pattern::many
§Example
use {
shrimple_parser::{
Pattern,
parser::one,
pattern::{ascii_digit, Many},
},
core::convert::Infallible,
};
// Matches 0 or more ASCII digits from the start of the input.
assert_eq!(
one::<_, Infallible>(ascii_digit.many())("123abc"),
Ok(("abc", "123")),
);
// 0 matches is still a match, with an empty matched fragment.
assert_eq!(
one::<_, Infallible>(ascii_digit.many())("abc"),
Ok(("abc", "")),
);Tuple Fields§
§0: TTrait Implementations§
impl<T: Copy + Pattern> Copy for Many<T>
Source§impl<T: Pattern> Pattern for Many<T>
impl<T: Pattern> Pattern for Many<T>
Source§fn immediate_matches<I: Input>(&self, input: I) -> (I, I)
fn immediate_matches<I: Input>(&self, input: I) -> (I, I)
Repeating “0 or more T” is the same as “0 or more T”, so this delegates directly to
T’s implementation rather than looping on Pattern::immediate_match, which would
never terminate since Many::immediate_match never fails.
Source§fn trailing_matches_counted<I: Input>(&self, input: I) -> (I, usize)
fn trailing_matches_counted<I: Input>(&self, input: I) -> (I, usize)
See Many::immediate_matches for why this delegates straight to T instead of
looping on Pattern::trailing_match.
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 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_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 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<T> Freeze for Many<T>where
T: Freeze,
impl<T> RefUnwindSafe for Many<T>where
T: RefUnwindSafe,
impl<T> Send for Many<T>where
T: Send,
impl<T> Sync for Many<T>where
T: Sync,
impl<T> Unpin for Many<T>where
T: Unpin,
impl<T> UnsafeUnpin for Many<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for Many<T>where
T: 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.