pub enum Commit<T> {
Commit(T),
Peek(T),
}Expand description
Enum used to indicate if a parser committed any items of the stream it was given as an input.
This is used by parsers such as or and choice to determine if they should try to parse
with another parser as they will only be able to provide good error reporting if the preceding
parser did not commit to the parse.
Variants§
Commit(T)
Constructor indicating that the parser has committed to this parse. If a parser after this fails,
other parser alternatives will not be attempted (CommitErr will be returned)
Peek(T)
Constructor indicating that the parser has not committed to this parse. If a parser after this fails,
other parser alternatives will be attempted (EmptyErr will be returned)
Implementations§
Source§impl<T> Commit<T>
impl<T> Commit<T>
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Extracts the contained value.
Sourcepub fn into_commit(self) -> Commit<T>
pub fn into_commit(self) -> Commit<T>
Converts self into the Commit state.
Sourcepub fn map<F, U>(self, f: F) -> Commit<U>where
F: FnOnce(T) -> U,
pub fn map<F, U>(self, f: F) -> Commit<U>where
F: FnOnce(T) -> U,
Maps over the contained value without changing the committed state.
pub fn merge(&self, current: Commit<T>) -> Commit<T>
Sourcepub fn combine<F, U, E>(
self,
f: F,
) -> Result<(U, Commit<()>), Commit<Tracked<E>>>
pub fn combine<F, U, E>( self, f: F, ) -> Result<(U, Commit<()>), Commit<Tracked<E>>>
Combines the Commit flags from self and the result of f.
Peek <> Peek -> Peek
Commit <> Peek -> Commit
Peek <> Commit -> Commit
Commit <> Commit -> Commit//Parses a character of string literal and handles the escaped characters \\ and \" as \
//and " respectively
fn char<Input>(input: &mut Input) -> StdParseResult<char, Input>
where Input: Stream<Token = char>,
{
let (c, committed) = satisfy(|c| c != '"').parse_stream(input).into_result()?;
match c {
//Since the `char` parser has already committed some of the input `combine` is used
//propagate the committed state to the next part of the parser
'\\' => committed.combine(|_| {
satisfy(|c| c == '"' || c == '\\')
.map(|c| {
match c {
'"' => '"',
'\\' => '\\',
c => c
}
})
.parse_stream(input)
.into_result()
}),
_ => Ok((c, committed))
}
}
let result = many(parser(char))
.easy_parse(r#"abc\"\\"#);
assert_eq!(result, Ok((r#"abc"\"#.to_string(), "")));
}pub fn combine_commit<F, U, E>(self, f: F) -> ParseResult<U, E>where
F: FnOnce(T) -> ParseResult<U, E>,
Trait Implementations§
impl<T> Copy for Commit<T>where
T: Copy,
impl<T> StructuralPartialEq for Commit<T>where
T: PartialEq,
Auto Trait Implementations§
impl<T> Freeze for Commit<T>where
T: Freeze,
impl<T> RefUnwindSafe for Commit<T>where
T: RefUnwindSafe,
impl<T> Send for Commit<T>where
T: Send,
impl<T> Sync for Commit<T>where
T: Sync,
impl<T> Unpin for Commit<T>where
T: Unpin,
impl<T> UnsafeUnpin for Commit<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for Commit<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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneExpand for Twhere
T: Clone,
impl<T> CloneExpand for Twhere
T: Clone,
fn __expand_clone_method(&self, _: &Scope) -> T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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> ⓘ
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> ⓘ
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