3 ms·
Not easily. Rust's type system has limits, and what you're talking about is something you'd probably want dependent types for. But it can catch lots of other l
by staticassertion 8y ago
Not easily. Rust's type system has limits, and what you're talking about is something you'd probably want dependent types for.
But it can catch lots of other logic errors.
The approach I have used in both mypy and rust is to encode state transitions into types. It's more elegant in Rust, and safer as well, but even with mypy it means I could be very sure about certain properties of my service (it was a sensitive service and I needed to be reasonably sure it wouldn't end up in an invalid state).
https://insanitybit.github.io/2016/05/30/beyond-memory-safety-with-types https://insanitybit.github.io/2016/05/30/beyond-memory-safet...
This is an example of the pattern.
When you take a "Type driven" approach to your code - stating your constraints upfront, and encoding them into your types - you can push a lot of the debug cycle to your compiler.