-
Notifications
You must be signed in to change notification settings - Fork 40
Add a derive macro for Prism #101
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
Conversation
f00c5da
to
3995b0e
Compare
That was the last force-push, testing whether existing |
|
||
Ok(quote! { | ||
#[derive(Clone)] | ||
#enum_vis struct #name; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we make it mod $enum_name { pub struct $variant_name; }
instead of struct $enum_name$variant_name
?
this is done in derive Lens
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that! I thought this kind of thing would require inherent associated types, great to hear it doesn't.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately this doesn't work because enum variants already exist in the value namespace (Option::Some
in the value namespace is a function from T
to Option<T>
).
Because of rust-lang/rust#76347, I only got errors after fully implementing this idea 🙄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh by the way the way druid does it / what almost worked wasn't mod $enum_name
, it was mod $mod_name {}
+ impl #enum_name { pub const Some: $mod_name = $mod_name::Some; }
.
The first approach immediately resulted in amibiguity errors between the enum and module.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's the broken code that uses associated constants: jplatte@7a62a9b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, personally I think it's worth having a derive crate for the nursery, because there will probably be other codegen we want to experiment with, and because druid already requires syn/quote. We should make sure we use the same versions, so users don't have to build them twice.
The couple of small issues that @maan2003 identified can either be fixed before merge, or in a follow-up PR, either is fine.
Cargo.toml dep versions aren't exact by degault. Virtually everything uses syn & quote 1.x.y, so only one will be compiled. |
Yes sorry was more just thinking out loud. I don't expect it to be an issue. |
Fixed the panic message and did some other refactorings, ready for another review :) |
This is awesome! @jplatte, thank you so much :) |
@maan2003 can this be merged? :) |
Sure! |
cc @xarvic 🙂