3 ms·
It's relatively easy to create a type which can't be created at all by functions outside the module it's defined in - add any private member. Then that module i
by vertex-four 10y ago
It's relatively easy to create a type which can't be created at all by functions outside the module it's defined in - add any private member. Then that module is in control of how it's created, and can set any restriction you like. This pattern is regularly used in Rust to ensure that types are always initialised correctly.
- fghgfdfg 10y agoSure, you can do things like that too in Ada. To some degree that might make sense sometimes, but having the option of an equally safe type that's used in a "normal" fashion, rather than something that has to go through the proper library interface has some advantages as well.
- vertex-four 10y agoIt's relatively uncommon in Rust in general to create types without going through their constructors.