#[repr(C)]pub struct Token {
pub token_type: i32,
pub token_value: Bytes,
pub loc: Loc,
}
Expand description
A token that is emitted by a lexer and consumed by a parser
Fields§
§token_type: i32
Numeric representation of the token type, e.g. 42 (for example) for tINTEGER
token_value: Bytes
Value of the token, e.g “42” for 42
loc: Loc
Location of the token
Implementations§
Source§impl Token
impl Token
Sourcepub fn into_bytes(self) -> Vec<u8> ⓘ
pub fn into_bytes(self) -> Vec<u8> ⓘ
Consumes a token and returns an owned byte array of the token value
Sourcepub fn as_str_lossy(&self) -> Result<&str, Utf8Error>
pub fn as_str_lossy(&self) -> Result<&str, Utf8Error>
Converts token value into &str
Sourcepub fn to_string_lossy(&self) -> String
pub fn to_string_lossy(&self) -> String
Converts token to a string, replaces unknown chars to U+FFFD
Sourcepub fn to_string(&self) -> Result<String, FromUtf8Error>
pub fn to_string(&self) -> Result<String, FromUtf8Error>
Converts token to a string
Sourcepub fn into_string(self) -> Result<String, FromUtf8Error>
pub fn into_string(self) -> Result<String, FromUtf8Error>
Consumes a token and converts it into a string
Sourcepub fn token_name(&self) -> &'static str
pub fn token_name(&self) -> &'static str
Returns name of the token
Trait Implementations§
impl Eq for Token
impl StructuralPartialEq for Token
Auto Trait Implementations§
impl Freeze for Token
impl RefUnwindSafe for Token
impl Send for Token
impl Sync for Token
impl Unpin for Token
impl UnwindSafe for Token
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more