Skip to main content

render_tokens

Function render_tokens 

Source
fn render_tokens(tokens: &TokenStream) -> String
Expand description

Renders a token stream as compact, canonical source text.

The rendering walks the token trees rather than calling TokenStream::to_string, whose spacing differs between the compiler and the proc-macro2 fallback and has changed across rustc releases. Idents and literals are rendered verbatim, so whitespace inside a string literal is preserved and distinguishes two bodies. Spacing between tokens follows fixed rules that read like formatted code for signatures and attribute arguments, and is merely deterministic for bodies.