So, I was writing some code and apparently R.A. didn't warn me about some erroneous stuff I had written in regards to how ownership works with lambdas.
So, a friend helped me rewrite some of my code, and this is just a play example, but their new code boils down to this:
let vec = Rc::new(RwLock::new( Vec::new() ));
let vec_rc = vec.clone();
let my_lambda = || -> () {
vec_rc.write().unwrap().push(/* ... */);
}
But what I don't understand is how this works if vec_rc
isn't mut
.
From my prior knowledge, mutable in Rust cascades; in other words, if the "master-containing" object is immutable the rest will have to be too.
Could I please get some clarity as to what goes on under the hood?
Or is their code erroneous too?