-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Clone
documentation can be confusing to beginners around "duplication" language
#141138
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
Comments
Cloning |
The docs for What would it mean to people new to the language, or have different notions of "duplicating an object" coming from a different programming language? This is probably a good opportunity to make the documentation clearer and more helpful to describe what exactly |
impl Clone
for Arc
/Rc
of Mutex
/RwLock
?Clone
documentation can be confusing to beginners around "duplication" language
…bilee std: clarify Clone trait documentation about duplication semantics Closes rust-lang#141138 The change explicitly explains that cloning behavior varies by type and clarifies that smart pointers (`Arc`, `Rc`) share the same underlying data. I've also added an example of cloning to Arc.
Rollup merge of #141215 - xizheyin:issue-141138, r=workingjubilee std: clarify Clone trait documentation about duplication semantics Closes #141138 The change explicitly explains that cloning behavior varies by type and clarifies that smart pointers (`Arc`, `Rc`) share the same underlying data. I've also added an example of cloning to Arc.
std: clarify Clone trait documentation about duplication semantics Closes rust-lang/rust#141138 The change explicitly explains that cloning behavior varies by type and clarifies that smart pointers (`Arc`, `Rc`) share the same underlying data. I've also added an example of cloning to Arc.
…bilee std: clarify Clone trait documentation about duplication semantics Closes rust-lang#141138 The change explicitly explains that cloning behavior varies by type and clarifies that smart pointers (`Arc`, `Rc`) share the same underlying data. I've also added an example of cloning to Arc.
Hi, I'm mainly using rust for developing application
I wonder is it safe to
impl Clone
forArc<Mutex>
Arc is a frequently used pattern for modifying data in multiple places.
However, if you end up cloning a parent struct that contains an Arc, it's hard to tell that the data inside is the same data without knowing more about the internal structure
For example
This becomes more likely to happen whenever you wrap it in a parent that implements
#[derive(Clone)]
.So I thought that struct with
Arc<Mutex>
shouldn't be able to implement clone as simply as writing#[derive(Clone)]
.Is this unsafe? or is it something that users should be aware of?
The text was updated successfully, but these errors were encountered: