Trait Parser

Source
pub trait Parser<T: TokenTreeExt> {
    type Output<'p, 'b>
       where Self: 'p;

    // Required method
    fn parse<'p, 'b>(
        &'p self,
        buf: &mut &'b TokenBuf<T>,
    ) -> Result<Self::Output<'p, 'b>, Error<T::Span>>;

    // Provided methods
    fn parse_all<'p, 'b>(
        &'p self,
        buf: &mut &'b TokenBuf<T>,
    ) -> Result<Self::Output<'p, 'b>, Error<T::Span>> { ... }
    fn optional(self) -> Optional<Self>
       where Self: Sized { ... }
}
Expand description

A parser for parsing values from a TokenBuf.

Required Associated Types§

Source

type Output<'p, 'b> where Self: 'p

The output type of this parser.

Required Methods§

Source

fn parse<'p, 'b>( &'p self, buf: &mut &'b TokenBuf<T>, ) -> Result<Self::Output<'p, 'b>, Error<T::Span>>

Parse a value from a TokenBuf using this parser.

The referenced &TokenBuf will be modified to point past the parsed tokens on success.

Provided Methods§

Source

fn parse_all<'p, 'b>( &'p self, buf: &mut &'b TokenBuf<T>, ) -> Result<Self::Output<'p, 'b>, Error<T::Span>>

Parse a value from a TokenBuf buffer, but return an error if there’s any tokens left in the buffer after parsing.

The referenced &TokenBuf will be modified to point past the parsed tokens on success. If parsing succeeds but there are tokens left in the buffer, the buffer will point to the left over tokens.

Source

fn optional(self) -> Optional<Self>
where Self: Sized,

Wrap this parser in Optional to make it always succeed and return an option.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T: TokenTreeExt, X: Parser<T>> Parser<T> for [X]

Source§

type Output<'p, 'b> = Vec<<X as Parser<T>>::Output<'p, 'b>> where Self: 'p

Source§

fn parse<'p, 'b>( &'p self, buf: &mut &'b TokenBuf<T>, ) -> Result<Self::Output<'p, 'b>, Error<T::Span>>

Implementors§

Source§

impl<P: PunctExt, F: MatchOpFn> Parser<<P as ProcMacro>::TokenTree> for OpParser<P, F>

Source§

type Output<'p, 'b> = Op<<P as ProcMacro>::Span> where Self: 'p

Source§

impl<T: TokenTreeExt> Parser<T> for Op<T::Span>

Source§

type Output<'p, 'b> = Op<<T as ProcMacro>::Span> where Self: 'p

Source§

impl<T: TokenTreeExt, M: Parser<T>, D: Parser<T>> Parser<T> for PunctuatedParser<T, M, D>

Source§

type Output<'p, 'b> = Punctuated<<M as Parser<T>>::Output<'p, 'b>, <D as Parser<T>>::Output<'p, 'b>> where Self: 'p

Source§

impl<T: TokenTreeExt, X: Parser<T>> Parser<T> for Optional<X>

Source§

type Output<'p, 'b> = Option<<X as Parser<T>>::Output<'p, 'b>> where Self: 'p