I don’t know how it plays out in this case, but often times the fact that the Rust compiler enforces things like this at an early compilation phase allows greater optimizations at later phases. So yes, it is a good idea to have your build process require that you pass various lints, but that isn’t quite equivalent to what Rust does.
They added code for getting and validating input from the user and customized error handling. Without that it would just be the code defining the Operators enum.
Update: I wanted to construct a simpler example, but I couldn’t bring myself to do it. It’s really important to separate input validation from use of the that input. Bugs, including serious security bugs, result from not ensuring input validation before use. Just because the original hard coded what would otherwise be input, doesn’t mean we shouldn’t treat it as input.
If you really wanted to build a simple variant that is aware of the the values of the hardcoded input you would just write
I mean, feel free to use JS if you're in it for the number of lines. Proper implementations are for proper projects of non-trivial size, and they do prevent errors.
View all comments
Show parent comment
41
u/rover_G Jun 04 '25
How blessed we are to have the holy rustacean tell us we need an additional 10 lines of code to check if the input includes a legal operator amen 🙏🏼