I am trying to wrap my head around Rust smart pointer architecture (full disclosure: C++ background). Most of the restrictions started to actually make sense, but Rc::get_mut() still seems to be overly restrictive – namely it requires no weak pointers.
I wrote a test program to learn how pointer work, and everything else except Rc::get_mut() works as I expect it: If I have only one strong pointer and a weak pointer (or several weak ones), I can drop the strong one forgetting the stored value and I can unwrap it, getting the stored value (as mutable if desired) and consuming the pointer, in both cases weak pointers will fail to upgrade afterwards. However, weak pointers prevent me from mutating the value.
The code is here https://play.rust-lang.org/?gist=4ba8c7195d4f4a7b4d6a655485490f44&version=stable
The effect of this restriction seems to be “If you can reach a value via weak pointer, then this value is constant”. What I fail to understand is the rationale behind this, what kind of bad scenarios does it prevent?
Any help will be appreciated. Thanks!