Skip to main content

slice

Function slice 

Source
pub fn slice<'a>(node: Node<'_>, source: &'a str) -> &'a str
Expand description

Verbatim source text spanned by node, or "" when the byte range is not a valid str boundary (adversarial or partially-parsed input).

This is the single “slice a node’s bytes” primitive. It replaces the per-language source.get(node.byte_range()).unwrap_or("") copies and the panicking &source[node.byte_range()] slicers (bad ranges now yield "" instead of panicking). Use node_source_text_trimmed when surrounding whitespace must be dropped, and node_ident_text when a language sigil (r#, @) must be normalized off identifier tokens.