Skip to content

add an assign default method to Clone #10240

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

Closed
thestinger opened this issue Nov 2, 2013 · 2 comments
Closed

add an assign default method to Clone #10240

thestinger opened this issue Nov 2, 2013 · 2 comments
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. I-slow Issue: Problems and improvements with respect to performance of generated code.

Comments

@thestinger
Copy link
Contributor

The following pattern is common:

a = b.clone()

However, it is much more inefficient than it could be for a type like a vector, where the allocation on the LHS can often be reused. I previously proposed a trait for this, but now that default methods work that's unnecessary.

@Kimundi
Copy link
Member

Kimundi commented Nov 3, 2013

I'm assuming you mean something like this?

trait Clone {
    ...
    fn clone_into(&self, other: &mut Self) {
        *other = self.clone();
    }
}
...
b.clone_into(a)

Definitively useful, and something I have wanted too occasionally.

@thestinger
Copy link
Contributor Author

Yes, like that, with types like vectors overriding it for performance.

bors added a commit that referenced this issue Nov 9, 2013
flip1995 pushed a commit to flip1995/rust that referenced this issue Jun 30, 2023
…trigger_on_expect, r=dswij

[`missing_panics_doc`]: pickup expect method

close rust-lang#10240

*Please write a short comment explaining your change (or "none" for internal only changes)*

changelog: [`missing_panics_doc`]: pickup expect method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. I-slow Issue: Problems and improvements with respect to performance of generated code.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants