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

auto_impl for trait objects? #49

Closed
jsgf opened this issue Mar 21, 2019 · 3 comments
Closed

auto_impl for trait objects? #49

jsgf opened this issue Mar 21, 2019 · 3 comments

Comments

@jsgf
Copy link

jsgf commented Mar 21, 2019

The use-case I run into most often is boilerplate for:

trait MyTrait {
...
}

impl MyTrait for Box<dyn MyTrait> {
// shim methods
}

Would it be possible to extend auto_impl to this case?

It would also need to support generating impls with autotraits/lifetimes:

impl MyTrait for Box<dyn MyTrait + Sync /* and/or 'static, Send, etc */> {
...
@LukasKalbertodt
Copy link
Member

LukasKalbertodt commented Mar 24, 2019

It would be absolutely possible to extend auto_impl for this use case! But at the same time, we should also support &dyn Trait, &mut dyn Trait, Rc<dyn Trait> and Arc<dyn Trait>. So basically every "pointer type" we currently support, only with a trait object.

I'm not quite sure how much work that would be. Hopefully we don't have to copy all the code for the other types, but can instead abstract somehow. Also the Send, Sync and lifetime bounds could be complicated. Mhhh...

Maybe it could be worth it to rewrite much of what we have: instead of hand coding each type we support, we define a table where we list each type and what restrictions it has. Then our system would be super generic and adding types would be easy.

I won't have time in the next months to implement this, but I could help you out if you want to try it!

@jsgf
Copy link
Author

jsgf commented Mar 25, 2019

I had a poke around the source and came to similar conclusions. I was thinking of adding it as something like #[auto_traitobj(&, Rc, Arc + Sync + 'static)] - ie, basically the same syntax but with the ability to append marker traits.

As far as codegen goes, it would be nice to avoid duplicating all the existing code, but I haven't looked at it closely enough yet to work out how to do that.

@jsgf
Copy link
Author

jsgf commented Jul 11, 2019

#52 addresses this more precisely.

@jsgf jsgf closed this as completed Jul 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants