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

Support traits with generic type parameters #10

Open
spersson opened this issue Sep 6, 2018 · 4 comments
Open

Support traits with generic type parameters #10

spersson opened this issue Sep 6, 2018 · 4 comments

Comments

@spersson
Copy link

spersson commented Sep 6, 2018

mopafy!(IoHandler<S>);

error: no rules expected the token <

Is there any simple work-around?

@chris-morgan
Copy link
Owner

This seems a fair enough request. I’d add to it where clauses, though that’ll require the “only core” invocation to change.

My first attempt at implementing it, however, is failing due to what looks like macro hygiene, and my recollection of the workaround for that seems no longer to work. (It’s been a few years since I’ve written any bleeding-edge macros.)

We could contemplate switching it to a derive attribute, which would save duplication of name and bounds and make it work, but it’s not actually deriving a trait (rather it’s adding methods to the trait object), so something like #[derive(AnyMethods)] with an optional #[mopa_only_core] attribute doesn’t feel quite right. I may consult with others to reckon whether it seems reasonable or not.

@dhardy
Copy link

dhardy commented Jan 17, 2019

downcast-rs already supports generic type parameters, so you could use that for inspiration. From my own trials with macros, I'd say this is possible in most cases using declarative macros, but sometimes painful and I could never get good support for lifetimes. Procedural macros are much more capable, yet that requires another crate.

BTW why are there two crates doing exactly the same thing?

@chris-morgan
Copy link
Owner

mopa predates downcast-rs by almost a year. I have never actually looked into downcast-rs, so I’m not sure what the differences may be.

@dhardy
Copy link

dhardy commented Jan 17, 2019

downcast-rs supports generics but not no_std and doesn't bother with your __ imports module (presumably because if you assume std then the names are predictable enough).

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

3 participants