Hello there Rustacians
I’m reading the Rust book in my spare time for some time now and got to the topic of interior mutability.
Having a C++ background I know similiar concepts from C++ as well like
mutable and I’m really bugged by these things in C++ all the time because it let’s you do things that you wouldn’t expect from the public API.
Everytime I see constant methods in our code at work that uses some of these “hacks” as I call them to bypass the const mechanism it makes me sick because it just doesn’t feels right to do these things.
I also never got any real use case for these hacks until I read about interior mutability in the Rust book which showcases this feature in a unit testing-like scenario.
I never thought about this so far but it kind of makes sense to be able to do this in this specific scenario where the public API of some trait might get in the way.
Apart from that my mood got worse as soon as I read about Rust having these “hacks” too.
So what I really would like to know now is what real world usecases there might be other than the unit testing scenario mentioned that really need interior mutability and cannot be solved in other ways?
Would be really great to hear some examples