-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Make Arc cloning mechanics clearer in module docs #53782
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,9 +49,9 @@ const MAX_REFCOUNT: usize = (isize::MAX) as usize; | |
/// | ||
/// The type `Arc<T>` provides shared ownership of a value of type `T`, | ||
/// allocated in the heap. Invoking [`clone`][clone] on `Arc` produces | ||
/// a new pointer to the same value in the heap. When the last `Arc` | ||
/// pointer to a given value is destroyed, the pointed-to value is | ||
/// also destroyed. | ||
/// a new pointer to the same `Arc` reference value in the heap. When the last | ||
/// `Arc` pointer to a given value is destroyed, the pointed-to value is also | ||
/// destroyed. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds better now! |
||
/// | ||
/// Shared references in Rust disallow mutation by default, and `Arc` is no | ||
/// exception: you cannot generally obtain a mutable reference to something | ||
|
@@ -107,7 +107,8 @@ const MAX_REFCOUNT: usize = (isize::MAX) as usize; | |
/// // The two syntaxes below are equivalent. | ||
/// let a = foo.clone(); | ||
/// let b = Arc::clone(&foo); | ||
/// // a and b both point to the same memory location as foo. | ||
/// // a and b both point to the same memory location where foo resides | ||
/// // (not where the value wrapped by foo resides). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In fact There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As per your other comment, I agree, will remove this. |
||
/// ``` | ||
/// | ||
/// The [`Arc::clone(&from)`] syntax is the most idiomatic because it conveys more explicitly | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be more accurate to say "produces a new
Arc
pointing to the same value in the heap". The source might make it clearer.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooh it works like that! So the internal reference is cloned. Been hearing varying descriptions on how it works. I can change it to reflect that soon. Thanks for clarifying.