Adjust documentation of Arc::make_mut
Related discussion in the users forum: https://users.rust-lang.org/t/what-s-this-alleged-difference-between-arc-make-mut-and-rc-make-mut/63747?u=steffahn Also includes small formatting improvement in the documentation of `Rc::make_mut`. This commit makes the two documentations in question complete analogs. The previously claimed point in which one "differs from the behavior of" the other turns out to be incorrect, AFAIK. One remaining inaccuracy: `Weak` pointers aren't disassociated from the allocation but only from the contained value, i.e. in case of outstanding `Weak` pointers there still is a new allocation created, just the call to `.clone()` is avoided, instead the value is moved from one allocation to the other.
This commit is contained in:
parent
4968a8bbd1
commit
51d598ec28
2 changed files with 30 additions and 14 deletions
|
@ -1115,11 +1115,11 @@ impl<T: Clone> Rc<T> {
|
|||
///
|
||||
/// let mut data = Rc::new(5);
|
||||
///
|
||||
/// *Rc::make_mut(&mut data) += 1; // Won't clone anything
|
||||
/// let mut other_data = Rc::clone(&data); // Won't clone inner data
|
||||
/// *Rc::make_mut(&mut data) += 1; // Clones inner data
|
||||
/// *Rc::make_mut(&mut data) += 1; // Won't clone anything
|
||||
/// *Rc::make_mut(&mut other_data) *= 2; // Won't clone anything
|
||||
/// *Rc::make_mut(&mut data) += 1; // Won't clone anything
|
||||
/// let mut other_data = Rc::clone(&data); // Won't clone inner data
|
||||
/// *Rc::make_mut(&mut data) += 1; // Clones inner data
|
||||
/// *Rc::make_mut(&mut data) += 1; // Won't clone anything
|
||||
/// *Rc::make_mut(&mut other_data) *= 2; // Won't clone anything
|
||||
///
|
||||
/// // Now `data` and `other_data` point to different allocations.
|
||||
/// assert_eq!(*data, 8);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue