syn::parse

Trait Parser

Source
pub trait Parser: Sized {
    type Output;

    // Required method
    fn parse2(self, tokens: TokenStream) -> Result<Self::Output>;

    // Provided methods
    fn parse(self, tokens: TokenStream) -> Result<Self::Output> { ... }
    fn parse_str(self, s: &str) -> Result<Self::Output> { ... }
}
Available on crate feature parsing only.
Expand description

Parser that can parse Rust tokens into a particular syntax tree node.

Refer to the module documentation for details about parsing in Syn.

Required Associated Types§

Required Methods§

Source

fn parse2(self, tokens: TokenStream) -> Result<Self::Output>

Parse a proc-macro2 token stream into the chosen syntax tree node.

This function enforces that the input is fully parsed. If there are any unparsed tokens at the end of the stream, an error is returned.

Provided Methods§

Source

fn parse(self, tokens: TokenStream) -> Result<Self::Output>

Available on crate feature proc-macro only.

Parse tokens of source code into the chosen syntax tree node.

This function enforces that the input is fully parsed. If there are any unparsed tokens at the end of the stream, an error is returned.

Source

fn parse_str(self, s: &str) -> Result<Self::Output>

Parse a string of Rust code into the chosen syntax tree node.

This function enforces that the input is fully parsed. If there are any unparsed tokens at the end of the string, an error is returned.

§Hygiene

Every span in the resulting syntax tree will be set to resolve at the macro call site.

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.

Implementors§

Source§

impl<F, T> Parser for F
where F: FnOnce(ParseStream<'_>) -> Result<T>,