pub struct Lexer<'t> { /* private fields */ }
Expand description
The Lexer iterates over the characters in a body of text, searching for Tokens.
§Examples
// Read in your code from somewhere
let some_code = "
fn main () {
// TODO: code goes here!
}
";
// Create a lexer over your code
let mut lexer = Lexer::new(some_code);
// Scan for a single token
let first_token = lexer.scan()?;
println!("{first_token:?}");
// Loop over all the rest of the tokens
for token in lexer {
match token {
Ok(token) => println!("{token:?}"),
Err(e) => eprintln!("{e:?}"),
}
}
Implementations§
Trait Implementations§
Auto Trait Implementations§
impl<'t> Freeze for Lexer<'t>
impl<'t> RefUnwindSafe for Lexer<'t>
impl<'t> Send for Lexer<'t>
impl<'t> Sync for Lexer<'t>
impl<'t> Unpin for Lexer<'t>
impl<'t> UnwindSafe for Lexer<'t>
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