Sane Handling of `Mutex>>>`
โ Rust ๐ 2025-07-31 ๐ค surdeus ๐๏ธ 14Iโm working with a bit of code where I want to store references between objects and weak back-references. At first I had it working with Rc and RefCell types, but now I realize Iโm A) sending these objects across thread in the GUI, and B) going to eventually want to operate on the logical Vec<T> in parallel.
Enter Arc and Mutex, which Iโve effectively replaced for Rc and RefCell one-to-one.
Now Iโm wondering if thereโs a better way to do this while preserving the ability to mutate the Vec and also mutate the inner T objects. Iโm sorta guessing Iโm stuck with this, which if true, leaves me wondering if there are patterns I can use that make this less of a mess of unwrap or PoisonError handling code.
For example this Rc<RefCell> code:
assert_eq!(lot.records.borrow()[0].borrow().uuid, record.borrow().uuid);
Turns into:
assert_eq!(
lot.records.lock().unwrap()[0].lock().unwrap().uuid,
record.lock().unwrap().uuid
);
Iโve decided for the moment that propagating panics is probably the best choice, but Iโm open to suggestions.
5 posts - 3 participants
๐ท๏ธ Rust_feed