macro
syn: parse Rust syntax into an AST
syn is an external parser, not a compiler built-in. Here it parses a function into a structured representation. The full feature enables ItemFn. Parsing does not establish type correctness. Example: external-dependency project; see fixtures/external-token-tools/src/bin/syn.rs. This caller is not a standalone rustc program. Expected stdout (not executed): 'total\n' Common mistake: Using whitespace splitting to parse arbitrary Rust syntax.
Formal Syntax & Structure
rust syntaxrust
syn::parse_str::<syn::ItemFn>(source)Working Example
Example Snippetrust
fn main() { let item: syn::ItemFn = syn::parse_str("fn total(x: u32) -> u32 { x + 1 }").unwrap(); println!("{}", item.sig.ident); }