pub struct Context(/* private fields */);Expand description
The hygiene context of a token: which expansion, if any, introduced it.
A context is a small copyable handle. Context::ROOT is the context of
every token written directly in source; every other context is minted by an
Expander when a macro’s template introduces a token, and
the expander can report where it came from through
origin.
Two identifiers with the same spelling denote the same binding only if their contexts are equal too. That single rule is what keeps a macro’s internal names from colliding with the names at its call site.
Contexts are only meaningful to the expander that minted them; a context from one expander carries no information in another.
§Examples
use macro_lang::Context;
let ctx = Context::ROOT;
assert!(ctx.is_root());
assert_eq!(ctx.as_u32(), 0);
assert_eq!(ctx.to_string(), "#0");Implementations§
Source§impl Context
impl Context
Sourcepub const ROOT: Self
pub const ROOT: Self
The context of tokens written directly in source, introduced by no expansion.
Sourcepub const fn is_root(self) -> bool
pub const fn is_root(self) -> bool
Returns true for Context::ROOT — a token no expansion introduced.
§Examples
use macro_lang::Context;
assert!(Context::ROOT.is_root());
assert!(Context::default().is_root());