[][src]Function syn::parse_str

pub fn parse_str<T: Parse>(s: &str) -> Result<T>

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

use syn::{Expr, Result};

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