this post was submitted on 19 Jun 2023
4 points (100.0% liked)
Rust Programming
8176 readers
10 users here now
founded 5 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
You'll notice that new is not a keyword or any special rust thing. It's actually a software design pattern called a smart constructor, and validation is part of the intent. Pattern wise putting this into a smart constructor and encapsulating changes to this value is, I believe, idiomatic.
IIUC rust does not have a type system where you can give numeric bounds. Creating one would likely mean you'd need to define all the maths, which is likely not worth it.
You reminded me of a deeply amusing story of solving the 4 queens problem with just the type system.