macro
TokenStream: iterate over syntax
A token stream can be traversed without first converting it into a string. Count top-level trees rather than characters; a bracketed group counts as one tree. Example: two-crate workspace; see fixtures/proc-macro-workspace/consumer/src/bin/token_stream.rs. This caller is not a standalone rustc program. Expected stdout (not executed): '3\n' Common mistake: Assuming whitespace-separated words match token boundaries.
Formal Syntax & Structure
rust syntaxrust
input.into_iter()Working Example
Example Snippetrust
use teaching_macros::token_count;fn main() { println!("{}", token_count!(x + (y))); }