2 ms·
How does Rust solve this problem?
by miohtama 2y ago
How does Rust solve this problem?
- nitnelave 2y agoDeep const: since you have a (const) ref to the variable, you cannot access any of its parts mutably. Of course, RefCell and co are not allowed, I suppose.
- PoignardAzur 2y agoInternally mutable types are allowed, but doing internal mutation isn't. So a const function can return a cell, for instance, as long as the cell isn't mutated inside the function.
- ironhaven 2y agoIt doesn't, you can not dynamically allocate memory in const functions even temporally. Rust was designed with the benefit of hindsight, so the well understood parts of const evaluation are stable and don't paint the syntax in a corner requiring `constexpr` and `consteval` keywords in the future.