Vim Practice
· 2 min read
Suppose you are writing a lexical analyzer(Lexer
), and you want return some customized errors while the lexer scan tokens,
and there are 3 possibel error will happens:
SO you can define the errors with a rust enum
:
pub enum LexerError {
InvalidToken(char),
InvalidString(String),
InvalidNum(String),
}