Re:Should Small Rust Structs be Passed by-copy or by-borrow?
by maxbond on Saturday December 31, 2022 @09:23PM
(#34202945)
Indeed, you can use interior mutability to accomplish this:
https://doc.rust-lang.org/reference/interior-mutability.html
Usually (read: near universally) something that provides interior mutability will implement a runtime check to protect you (eg, a lock), but you could make a footgun if you were cavalier about it. And recent I misused a framework (I kept a value returned by the framework around that should've been dropped) without realizing it was holding locks internal to the framework, and ended up with a tricky to diagnose deadlock (though only tricky before I hadn't read the documentation as closely as I should've).
I got very little experience in rust either though, so there might be a way I'm just not aware of to circumvent this check