pub trait Parser: Sized {
    type Output;
    fn parse2(self, tokens: TokenStream) -> Result<Self::Output>;

    fn parse_str(self, s: &str) -> Result<Self::Output> { ... }
}
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.

This trait is available only if Syn is built with the "parsing" feature.

Associated Types

Required methods

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

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

Provided methods

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

This function will check 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.

Implementors