Struct Chain

Source
pub struct Chain<T, U, P1, P2> { /* private fields */ }
Expand description

Chains two parsers together.

Follows error coercion rules.

let mut input = ParserString::from("abc   ");
let (string, after) = word.chain(whitespace).parse(&mut input)?;

assert_eq!(string, "abc");
assert_eq!(after, 3);

Implementations§

Source§

impl<T, U, P1, P2, E> Chain<T, U, P1, P2>
where P1: Parser<T>, E: Into<P1::Err>, P2: Parser<U, Err = E>,

Source

pub fn new(p1: P1, p2: P2) -> Self

Constructs this parser.

Trait Implementations§

Source§

impl<T, U, P1, P2, E> Parser<(T, U)> for Chain<T, U, P1, P2>
where P1: Parser<T>, E: Into<P1::Err>, P2: Parser<U, Err = E>,

Source§

type Err = <P1 as Parser<T>>::Err

The error type this parser can return
Source§

fn parse(&self, s: &mut ParserString) -> Result<(T, U), Self::Err>

Run this parser, using a ParserString.
Source§

fn try_parse(&self, s: &mut ParserString) -> Result<T, Self::Err>

Run this parser without affecting the string on failure. In other words, the string will be “rewinded” on failure.
Source§

fn chain<U, P2: Parser<U, Err = E>, E: Into<Self::Err>>( self, other: P2, ) -> Chain<T, U, Self, P2>

Constructs a Chain combinator.
Source§

fn or<P2: Parser<T, Err = E>, E: Into<Self::Err>>( self, other: P2, ) -> Or<T, E, Self, P2>

Constructs a Or combinator.
Source§

fn many(self) -> Many<T, Self>

Constructs a Many combinator.
Source§

fn many1(self) -> Many1<T, Self>

Constructs a Many1 combinator.
Source§

fn map<U: 'static>( self, f: impl Fn(T) -> U + 'static, ) -> impl Parser<U, Err = Self::Err>

Apply a function to the output of this parser on success.
Source§

fn map_err<E: 'static>( self, f: impl Fn(Self::Err) -> E + 'static, ) -> impl Parser<T, Err = E>

Apply a function to the Err output of this parser on failure.
Source§

fn and_then<U: 'static, E: Into<Self::Err>>( self, f: impl Fn(T) -> Result<U, E> + 'static, ) -> impl Parser<U, Err = Self::Err>

Applies a function to the output of this parser on success, using error coercion rules.
Source§

fn after<U, P2: Parser<U, Err = E>, E: Into<Self::Err>>( self, other: P2, ) -> impl Parser<T, Err = Self::Err>

Similar to Chain, but only keeps the output of the first parser.
Source§

fn replace<U, P2: Parser<U, Err = E>, E: Into<Self::Err>>( self, other: P2, ) -> impl Parser<U, Err = Self::Err>

Similar to Chain, but only keeps the output of the second parser.
Source§

fn convert_err<E: From<Self::Err> + 'static>(self) -> impl Parser<T, Err = E>

Explicitly sets the target error type of this parser. Can help with type inference.

Auto Trait Implementations§

§

impl<T, U, P1, P2> Freeze for Chain<T, U, P1, P2>
where P1: Freeze, P2: Freeze,

§

impl<T, U, P1, P2> RefUnwindSafe for Chain<T, U, P1, P2>

§

impl<T, U, P1, P2> Send for Chain<T, U, P1, P2>
where P1: Send, P2: Send, T: Send, U: Send,

§

impl<T, U, P1, P2> Sync for Chain<T, U, P1, P2>
where P1: Sync, P2: Sync, T: Sync, U: Sync,

§

impl<T, U, P1, P2> Unpin for Chain<T, U, P1, P2>
where P1: Unpin, P2: Unpin, T: Unpin, U: Unpin,

§

impl<T, U, P1, P2> UnwindSafe for Chain<T, U, P1, P2>
where P1: UnwindSafe, P2: UnwindSafe, T: UnwindSafe, U: 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> 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, 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.