pub struct TokenRef<'src> {
pub kind: TokenKind,
pub text: &'src str,
pub start: usize,
pub end: usize,
}Expand description
Borrowed view over token data for allocation-sensitive paths.
Unlike Token, this type borrows source text and does not allocate.
Convert to Token explicitly with TokenRef::to_owned_token or From.
Fields§
§kind: TokenKindToken classification for parser decision making
text: &'src strBorrowed source text slice
start: usizeStarting byte position for error reporting and location tracking
end: usizeEnding byte position for span calculation and navigation
Implementations§
Source§impl<'src> TokenRef<'src>
impl<'src> TokenRef<'src>
Sourcepub fn new(kind: TokenKind, text: &'src str, start: usize, end: usize) -> Self
pub fn new(kind: TokenKind, text: &'src str, start: usize, end: usize) -> Self
Create a borrowed token view with the given kind, source text, and byte span.
Sourcepub fn try_new(
kind: TokenKind,
text: &'src str,
start: usize,
end: usize,
) -> Result<Self, TokenSpanError>
pub fn try_new( kind: TokenKind, text: &'src str, start: usize, end: usize, ) -> Result<Self, TokenSpanError>
Create a borrowed token view with checked span ordering.
Unlike TokenRef::new, this rejects spans where end < start.
Sourcepub fn new_checked(
kind: TokenKind,
text: &'src str,
start: usize,
end: usize,
) -> Result<Self, TokenSpanError>
pub fn new_checked( kind: TokenKind, text: &'src str, start: usize, end: usize, ) -> Result<Self, TokenSpanError>
Create a borrowed token view while enforcing span invariants.
Rules:
start <= end- zero-length spans are accepted for EOF and explicit synthetic unknown tokens
Sourcepub fn display_name(self) -> &'static str
pub fn display_name(self) -> &'static str
Return a human-readable display name for this token.
Sourcepub fn to_owned_token(self) -> Token
pub fn to_owned_token(self) -> Token
Convert this borrowed token view into an owned Token.