pub struct Token {
pub kind: Kind,
pub flags: Flags,
pub keyword: u16,
pub start: u32,
pub end: u32,
}Expand description
One token. Twelve bytes, no allocation, no owned text.
Fields§
§kind: KindWhat it is.
flags: FlagsWhat was in the gap before it.
keyword: u16The index into generated::keywords::KEYWORDS, or NOT_A_KEYWORD.
Resolved once here rather than at every position the matcher considers the token, because the matcher considers most tokens many times and the fold plus binary search is the expensive part of asking.
start: u32Where it starts, as a byte offset into the query.
end: u32One past where it ends.
Implementations§
Source§impl Token
impl Token
Sourcepub fn text(self, query: &str) -> &str
pub fn text(self, query: &str) -> &str
The text of this token, given the query it came from.
Both bounds came from a scan over the same string and always land on a character boundary,
so this cannot panic on well formed input. It is written as a slice rather than a checked
get because a token whose bounds are not on a boundary is a bug in the tokenizer and
silently returning nothing would hide it.