Follow

This week's 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.

· · Web · 1 · 0 · 1

@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.

Sign in to participate in the conversation
Mauvestodon

Escape ship from centralized social media run by Mauve.