macro
proc-macro2: testable token utilities
The external proc-macro2 crate provides token operations that can be used outside a compiler macro entry point. Separate token transformation helpers from the compiler-facing wrapper, so ordinary tests can exercise their logic. Example: external-dependency project; see fixtures/external-token-tools/src/bin/proc_macro2.rs. This caller is not a standalone rustc program. Expected stdout (not executed): '3\n' Common mistake: Calling compiler-backed proc_macro operations directly in a regular application test.
Formal Syntax & Structure
rust syntaxrust
let tokens: proc_macro2::TokenStream = source.parse()?;Working Example
Example Snippetrust
fn main() { let tokens: proc_macro2::TokenStream = "x + 1".parse().unwrap(); println!("{}", tokens.into_iter().count()); }