Function syn::parse_str

source ·
pub fn parse_str<T: Parse>(s: &str) -> Result<T>
Available on crate feature parsing only.
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.


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


use syn::{Expr, Result};

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