Function syn::parse_str [] [src]

pub fn parse_str<T: Synom>(s: &str) -> Result<T, ParseError>

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

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

Hygiene

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

Examples

extern crate syn;

use syn::Expr;

fn run() -> Result<()> {
    let code = "assert_eq!(u8::max_value(), 255)";
    let expr = syn::parse_str::<Expr>(code)?;
    println!("{:#?}", expr);
    Ok(())
}