Struct transduce::Parser

source ·
pub struct Parser<'input, Inside: Parse<'input>>(_, _);
Expand description

Wrapper around a parser to work with the orphan rule.

Implementations§

source§

impl<'input, Inside: Parse<'input>> Parser<'input, Inside>

source

pub const fn new(inside: Inside) -> Self

Create a Parser without worrying about workarounds like PhantomData.

source

pub fn parse( &self, input: &'input [Inside::Input] ) -> Result<Inside::Output, String>

Parse a list of items (usually characters, in which case this “list of characters” is effectively a string).

Errors

If parsing fails, if we run out of input, or if we have leftover input afterward.

source

pub fn parse_or_panic(&self, slice: &'input [Inside::Input]) -> Inside::Output

Parse a list of items (usually characters, in which case this “list of characters” is effectively a string).

Panics

If parsing fails, if we run out of input, or if we have leftover input afterward.

source

pub const fn discard_left<Right: Parse<'input, Input = Inside::Input>>( self, right: Parser<'input, Right> ) -> Parser<'input, DiscardLeft<'input, Inside, Right>>

Consume this parser and integrate it into a two-part parser that returns only the second result.

source

pub const fn discard_right<Right: Parse<'input, Input = Inside::Input>>( self, right: Parser<'input, Right> ) -> Parser<'input, DiscardRight<'input, Inside, Right>>

Consume this parser and integrate it into a two-part parser that returns only the first result.

source

pub const fn both<Right: Parse<'input, Input = Inside::Input>>( self, right: Parser<'input, Right> ) -> Parser<'input, Both<'input, Inside, Right>>

Consume this parser and integrate it into a two-part parser that returns both results as a tuple.

source

pub const fn either<Right: Parse<'input, Input = Inside::Input, Output = Inside::Output>>( self, right: Parser<'input, Right> ) -> Parser<'input, Either<'input, Inside, Right>>

Consume this parser and integrate it into a two-part parser that returns the first one to succeed, or the second error if neither succeed.

source

pub const fn pipe<FinalOutput, Right: Fn(Inside::Output) -> Result<FinalOutput, String>>( self, right: Right ) -> Parser<'input, Pipe<'input, Inside, FinalOutput, Right>>

Consume this parser and integrate it into a two-part parser that pipes parsed output into a normal function and returns its output.

Trait Implementations§

source§

impl<'input, Left: Parse<'input>, Right: Parse<'input, Input = Left::Input>> BitAnd<Parser<'input, Right>> for Parser<'input, Left>

§

type Output = Parser<'input, Both<'input, Left, Right>>

The resulting type after applying the & operator.
source§

fn bitand(self, rhs: Parser<'input, Right>) -> Self::Output

Performs the & operation. Read more
source§

impl<'input, Left: Parse<'input>, Right: Parse<'input, Input = Left::Input, Output = Left::Output>> BitOr<Parser<'input, Right>> for Parser<'input, Left>

§

type Output = Parser<'input, Either<'input, Left, Right>>

The resulting type after applying the | operator.
source§

fn bitor(self, rhs: Parser<'input, Right>) -> Self::Output

Performs the | operation. Read more
source§

impl<'input, Left: Parse<'input>, FinalOutput, Right: Fn(Left::Output) -> Result<FinalOutput, String>> BitXor<Right> for Parser<'input, Left>

§

type Output = Parser<'input, Pipe<'input, Left, FinalOutput, Right>>

The resulting type after applying the ^ operator.
source§

fn bitxor(self, rhs: Right) -> Self::Output

Performs the ^ operation. Read more
source§

impl<'input, Inside: Clone + Parse<'input>> Clone for Parser<'input, Inside>

source§

fn clone(&self) -> Parser<'input, Inside>

Returns a copy 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<'input, Inside: Debug + Parse<'input>> Debug for Parser<'input, Inside>

source§

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

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

impl<'input, Inside: Parse<'input>> Parse<'input> for Parser<'input, Inside>

§

type Input = <Inside as Parse<'input>>::Input

Raw type, of which we parse a slice. E.g. u8 if we want to parse a string of bytes, not &[u8]: the slice is implied.
§

type Output = <Inside as Parse<'input>>::Output

Output of parsing a slice of Inputs.
source§

fn partial( &self, input: &'input [Self::Input] ) -> Result<(Self::Output, &'input [Self::Input]), ParseError>

Parse exactly one item of input; don’t continue without further instruction. Read more
source§

impl<'input, Left: Parse<'input>, Right: Parse<'input, Input = Left::Input>> Shl<Parser<'input, Right>> for Parser<'input, Left>

§

type Output = Parser<'input, DiscardRight<'input, Left, Right>>

The resulting type after applying the << operator.
source§

fn shl(self, rhs: Parser<'input, Right>) -> Self::Output

Performs the << operation. Read more
source§

impl<'input, Left: Parse<'input, Input = Right::Input>, Right: Parse<'input>> Shr<Parser<'input, Right>> for Parser<'input, Left>

§

type Output = Parser<'input, DiscardLeft<'input, Left, Right>>

The resulting type after applying the >> operator.
source§

fn shr(self, rhs: Parser<'input, Right>) -> Self::Output

Performs the >> operation. Read more

Auto Trait Implementations§

§

impl<'input, Inside> RefUnwindSafe for Parser<'input, Inside>where Inside: RefUnwindSafe,

§

impl<'input, Inside> Send for Parser<'input, Inside>where Inside: Send,

§

impl<'input, Inside> Sync for Parser<'input, Inside>where Inside: Sync,

§

impl<'input, Inside> Unpin for Parser<'input, Inside>where Inside: Unpin,

§

impl<'input, Inside> UnwindSafe for Parser<'input, Inside>where Inside: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.