This week's #Rust lesson was to wrap mutable bits of state in `Arc>` otherwise you may encounter issues with data not persisting even though you think you've got mutable references to it.
-
This week's #Rust lesson was to wrap mutable bits of state in `Arc<Mutex<>>` otherwise you may encounter issues with data not persisting even though you think you've got mutable references to it.
-
@mauve I feel like something in your explainer doesnβt quite sound right?
I don't know what youβre doing exactly, but the way I'd phrase it is: Rustβs borrowing rules require that each reference must be either mutable XOR shared. `Arc<Mutex<T>>` allows you to break that limitation and have a reference which is mutable AND shared.
idk, does that match the way you were thinking about it?
-
@yosh Ah! In this case the learned lesson was more about how rust passes by value by default and we were accidentally cloning state and needed to wrap it in a mutex to be able to actually mutate the one value.