When we want to extract the value inside the Arc
, we usually use:
pub fn get_mut(this: &mut Self) -> Option<&mut T>;
It's very rare to me that using a &mut Arc<T>
, I wondered why this function must take a &mut Self
? What's the danger if it takes a &Self
?
If it took &self
then you would still be able to dereference the Arc
with deref
and get another another reference to the same T
, thus breaking the borrowing rules.
1 Like
kpreid
April 1, 2023, 4:49pm
3
It would also be possible to clone the Arc
and get simultaneous access that way.
1 Like
Sorry for asking a silly question, I'v been coding for hours without sleeping, and now I'm experiencing some serious brain fog
system
Closed
June 30, 2023, 4:54pm
5
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.