# Function syn::parse_str

source · [−]

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

Expand description

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

This function is available only 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(())
    }