3 ms·
Rust is considering this under the name of "pattern types" [0][1]. If the full idea is realized, you should be able to handle strings and enums as well. There
by mbStavola 3y ago
Rust is considering this under the name of "pattern types" [0][1]. If the full idea is realized, you should be able to handle strings and enums as well.
There is also a PR for a minimal implementation using a macro and targeting integers specifically[2]. It's experimental and there is a chance this doesn't get stabilized, but here's hoping it makes it through!
[0]: https://github.com/rust-lang/rust/pull/107606 https://github.com/rust-lang/rust/pull/107606
[1]: https://cohost.org/oli-obk/post/165584-ranged-integers-via https://cohost.org/oli-obk/post/165584-ranged-integers-via
[2]: https://github.com/rust-lang/rust/pull/120131 https://github.com/rust-lang/rust/pull/120131
- phoehne 3y agoI’m glad to hear that. We’re moving stuff to Rust at work and it’s great at memory safety. Much better than relying on Unchecked_Deallocation. But that said, there are a lot of times when something can’t be out of a range, like voltage is from 0.00 to 1.85 in steps of 0.01. Ada is much better at safely specifying that range, while Rust will happily take values that are outside the acceptable range.
- binary132 3y agoAlmost as though in order to maintain runtime type invariants on values you must use some kind of function to “construct” them...
- pyjarrett 3y agoAda checks the ranges on types assigned to each other at compile time and then invariants on assignment and when passed as parameters. You can turn the runtime side of these checks on or off individually at the module level.
- kevlar700 3y agoThat's unfortunate. Ada is so much nicer to work with and Spark now has deallocation safety and memory leak prevention. https://youtu.be/97G1V2U8Drk?si=wNqNs1GiuO9ZdGwP https://youtu.be/97G1V2U8Drk?si=wNqNs1GiuO9ZdGwP
- kevlar700 3y agoI chose Ada over Rust for my company a few years ago and couldn't be happier. My entire embedded and tooling code bases are now Spark compatible. I don't believe any language can match Ada for drivers, memory register and network protocol handling.
- pjmlp 3y agoNVidia did as well for their car automation firmware.