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

Provide a syntax extension to derive traits for a newtype #19597

Closed
aochagavia opened this issue Dec 6, 2014 · 6 comments
Closed

Provide a syntax extension to derive traits for a newtype #19597

aochagavia opened this issue Dec 6, 2014 · 6 comments
Labels
A-syntaxext Area: Syntax extensions

Comments

@aochagavia
Copy link
Contributor

It would be nice to be able to do something like:

#[newtype_deriving(Add, Sub, Mul, Div)]
struct Centimeters(i32);

The current solution to this problem (implementing the traits manually), causes a lot of boilerplate and makes usage of newtypes less attractive.

If there is enough interest, I would love to submit a PR for this

cc @aturon

@ghost
Copy link

ghost commented Dec 6, 2014

cc #14047

@huonw
Copy link
Member

huonw commented Dec 6, 2014

I believe this is impossible as a syntax extension, since they have no access to the methods and method signatures of the trait to be able to create the impls. I'm willing to be proved wrong, but I also think this requires an RFC.

@huonw
Copy link
Member

huonw commented Dec 6, 2014

(At least, it is impossible to do for arbitrary traits.)

@aturon
Copy link
Member

aturon commented Dec 8, 2014

Yes, this definitely would need an RFC. That said, I would love functionality like this.

I'd suggest this issue be closed in favor of an issue in the RFC tracker.

@kmcallister
Copy link
Contributor

I think this is a good feature for a version 2 deriving system that isn't purely syntax-based.

@kmcallister kmcallister added the A-syntaxext Area: Syntax extensions label Jan 18, 2015
@steveklabnik
Copy link
Member

Closing in favor of rust-lang/rfcs#261

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-syntaxext Area: Syntax extensions
Projects
None yet
Development

No branches or pull requests

5 participants