Skip to content
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

Add an operator overload for clone() #2350

Closed
I3ck opened this Issue Feb 24, 2018 · 3 comments

Comments

Projects
None yet
2 participants
@I3ck
Copy link

I3ck commented Feb 24, 2018

Calling multiple functions which take their parameters by reference is quite convenient:

foo(&a);
bar(&a);
baz(&a);

But if functions are defined via move semantics, one has to explicitly clone non-Copy types:

foo(a.clone());
bar(a.clone());
baz(a.clone());
bab(a);

Also consider the usage of the vec! macro, to create a Vec of cloned values:

let v = vec![foo.clone(), bar.clone(), baz.clone(), a.clone(), b.clone(), c.clone()]

The visual noise gets rather bad.
I suggest introducing an operator similar to * and & which clones the value.
Above examples but with + defined as the clone()-operator (+ just being a suggestion, any character would do):

foo(+a);
bar(+a);
baz(+a);
bab(a);
let v = vec![+foo, +bar, +baz, +a, +b, +c]

@Centril Centril added the T-lang label Feb 24, 2018

@Centril

This comment has been minimized.

Copy link
Contributor

Centril commented Feb 24, 2018

This is better discussed over at internals.rust-lang.org which is more actively looked at. This repository should mainly be used to file full RFCs according to the template as pull requests. The issues filed here are not actively looked at by the teams.

@I3ck

This comment has been minimized.

Copy link
Author

I3ck commented Feb 24, 2018

Thanks for the information. I mirrored the suggestion https://internals.rust-lang.org/t/add-an-operator-overload-for-clone/6823

@Centril

This comment has been minimized.

Copy link
Contributor

Centril commented Feb 24, 2018

Great! Closing this one here then =)

@Centril Centril closed this Feb 24, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.