1
0
Fork 0

Change tokens to use &str w/lifetime instead of String

This commit is contained in:
Vili Sinervä 2025-01-21 20:26:18 +02:00
parent 65d437b324
commit dec0a0e154
No known key found for this signature in database
GPG key ID: DF8FEAF54EFAC996

View file

@ -45,16 +45,16 @@ impl TokenType {
}
#[derive(Debug, PartialEq)]
pub struct Token {
text: String,
pub struct Token<'source> {
text: &'source str,
token_type: TokenType,
loc: CodeLocation,
}
impl Token {
pub fn new(text: &str, token_type: TokenType, loc: CodeLocation) -> Self {
impl<'source> Token<'source> {
pub fn new(text: &'source str, token_type: TokenType, loc: CodeLocation) -> Self {
Self {
text: text.to_string(),
text,
token_type,
loc,
}