3 ms·
That is how I would handle that - you lex or parse your strings into an Option<Token> (or Result, etc), so that then all logic operating on the Token enum doesn
by shpongled 7y ago
That is how I would handle that - you lex or parse your strings into an Option<Token> (or Result, etc), so that then all logic operating on the Token enum doesnt need to worry about whether it's a correct value - it's statically enforced.
I personally find the most value out of sum types (enums with data) and the ability to use Option/Result with the try operator '?' for this kind of stuff, where you can float errors up the call chain
- larusso 7y agoOk I kind of doing that already. The main issue I have is that some data comes from configuration and I can’t create static values for those (URLs for example). Thanks