Arc_swap usage and &mut reference

How do I get a &mut to the pointee in a ArcSwap type? I did the following but it always returns None:
What am I doing wrong and any pointers of how to get it right?

let value = ArcSwap::new(Arc::new(T));
let value = value.load();
let mut value : Arc<T> = Arc::clone(&value);
let value = Arc::get_mut(&mut value);
if let Some(value) = value
       // I always come here.

Arc::get_mut can only work on Arcs that are not currently aliased. To get an unaliased Arc out of the ArcSwap, you would need to replace it with something else. That might not fit your use case though; alternatively, you could try designing the type within the Arc in a way that shared-reference access is sufficient, or you might need to use a Mutex.

Since this question features no actual practical problems, it's of course impossible to give specific advice on which of the many possible options to choose :slight_smile:

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.