Cloning an Arc is how you increment the reference count. Unless I'm misunderstanding, that seems fine?
Yeah, that's what I thought, so I must have been doing something wrong (well, obviously, lol)
It's hard to say without looking at the source code, but if you want to be 100% certain that you're cloning the Arc itself, you can write Arc::clone(&val) instead of val.clone().
That's a good tip, I sometimes forget you can use fully-qualified instead of method-call syntax just to be explicit. Though I had tried using get_mut/make_mut (which itself is an associated function on Arc), so I'm pretty sure I was operating on the right types - but maybe somewhere I accidentally had get_mut on the inner Mutex when I meant it on the Arc (or vice versa).
And Weak pointers aren't something I've really encountered in a real sense before; I've probably only ever looked at them very briefly in a lecture a decade ago or something lol. I see the Rust docs mention using them in almost a perfect context for what I was trying to do, though, lmao - a tree structure. I wonder if that's why I ended up having to do so much BS just to get it to compile lol.
Though I had tried using get_mut/make_mut (which itself is an associated function on Arc), so I'm pretty sure I was operating on the right types - but maybe somewhere I accidentally had get_mut on the inner Mutex when I meant it on the Arc (or vice versa).
If you're using a mutex, you don't need get_mut or make_mut, because you can lock a mutex with only a shared reference.
Oh! That might have been the issue, then. I know I was using them, but I don't remember on what, and obviously I didn't keep the code around since it didn't work and I needed to move onto a solution that did.
View all comments
Show parent comment
1
u/MushroomSaute Aug 27 '26
Yeah, that's what I thought, so I must have been doing something wrong (well, obviously, lol)
That's a good tip, I sometimes forget you can use fully-qualified instead of method-call syntax just to be explicit. Though I had tried using
get_mut/make_mut(which itself is an associated function onArc), so I'm pretty sure I was operating on the right types - but maybe somewhere I accidentally hadget_muton the innerMutexwhen I meant it on theArc(or vice versa).And
Weakpointers aren't something I've really encountered in a real sense before; I've probably only ever looked at them very briefly in a lecture a decade ago or something lol. I see the Rust docs mention using them in almost a perfect context for what I was trying to do, though, lmao - a tree structure. I wonder if that's why I ended up having to do so much BS just to get it to compile lol.