3 ms·
I would love to have an example of what exactly he is writing about. I spend most my time at the moment to rewrite some code from JS to Rust and still fight wit
by larusso 7y ago
I would love to have an example of what exactly he is writing about. I spend most my time at the moment to rewrite some code from JS to Rust and still fight with invariants. I would like to know how to achieve the 100% safety. I know that I get most of the null pointer exception etc handled with Option and Result structs. But if you need to deal with string values etc the compiler can’t really help out when the value is not the one you’re expecting. And I also moved most of these to enums.
- jacamera 7y ago> I would love to have an example of what exactly he is writing about. Thank you. This such a nothing article with a clickbait headline.
- dbtx 7y agoAlso flamebait.
- shpongled 7y agoThat 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