Change tokens to use &str w/lifetime instead of String
This commit is contained in:
parent
65d437b324
commit
dec0a0e154
1 changed files with 5 additions and 5 deletions
|
@ -45,16 +45,16 @@ impl TokenType {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub struct Token {
|
pub struct Token<'source> {
|
||||||
text: String,
|
text: &'source str,
|
||||||
token_type: TokenType,
|
token_type: TokenType,
|
||||||
loc: CodeLocation,
|
loc: CodeLocation,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Token {
|
impl<'source> Token<'source> {
|
||||||
pub fn new(text: &str, token_type: TokenType, loc: CodeLocation) -> Self {
|
pub fn new(text: &'source str, token_type: TokenType, loc: CodeLocation) -> Self {
|
||||||
Self {
|
Self {
|
||||||
text: text.to_string(),
|
text,
|
||||||
token_type,
|
token_type,
|
||||||
loc,
|
loc,
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue