Skip to main content

with_meaning

Function with_meaning 

Source
pub fn with_meaning<R>(token: &Token, f: impl FnOnce(Option<&Stored>) -> R) -> R
Expand description

Closure-based variant of lookup_meaning — avoids the per-call Stored::clone() when the caller only needs to inspect the meaning (e.g. extract a CS Token from an Expandable/Primitive definition). Stored::clone is ~1% of total instructions on siunitx-heavy fixtures (5M+ calls per run, each cloning a full Stored enum). This helper borrows the stored value instead.

For non-CS/ACTIVE tokens, passes Some(Stored::Token(*token)) — matching lookup_meaning’s fallback semantics. Note this requires a single stack allocation of Stored::Token (Copy), not a heap clone.