3 ms·
Are there languages that automatically extend this to things like data structure members? One of the things I like about the C++ const keyword is that if you de
by bathtub365 1y ago
Are there languages that automatically extend this to things like data structure members? One of the things I like about the C++ const keyword is that if you declare an instance of a struct/class as const it extends that to its members. If the instance isn’t const, you can still mutate them (as long as they aren’t declared const within the structure itself)
- orlp 1y agoRust works this way, yes. There are escape hatches though, which allow interior mutability.
- snalty 1y agoYeah, here's an example: https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=1c4609c5f0bca55613490f2a80d0c026 https://play.rust-lang.org/?version=stable&mode=debug&editio...
- School-Cotton 1y agoIf I understand what you’re asking correctly, rust is also like this. If you have a non-mut value of (or non-mut reference to) an object, you only get non-mut access to its members.