-
Notifications
You must be signed in to change notification settings - Fork 152
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
Re-export macros #170
Re-export macros #170
Conversation
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.
This makes a lot of sense to me! Thanks for putting together a PR :) I left a few comments and if you could add a few tests, that would be great.
Maybe just try re-exporting the strum derives from some nested module in the tests and make sure it still works. You could also use the debugging section to make sure the proper code is generated.
strum_macros/src/helpers/metadata.rs
Outdated
@@ -14,6 +15,7 @@ pub mod kw { | |||
|
|||
// enum metadata | |||
custom_keyword!(serialize_all); | |||
custom_keyword!(crate_path); |
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.
Did you say serde uses "crate?" Can we also do that for consistency?
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.
crate
is a Rust keyword, is it okay if I use Crate
instead?
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.
sorry for the delay getting back to you. thanks for your patience. I would prefer crate if we can since that's what serde does. Is there a technical reason we can't do that?
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.
Just overcome the technical difficulties, see the latest commit, now we have
#[derive(Debug, Eq, PartialEq, EnumIter)]
#[strum(crate = "nested::module::strum")]
enum Week {
Sunday,
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday,
}
Please review @Peternator7 |
lgtm! Thanks for the contribution. I'm on vacation next week, but I'll try and get a release out if I find a little time! |
Have a nice vacation!! |
Hi, this would be very useful for my crate, as I'm in the process of refactoring my framework to improve ergonomics, and strum is currently used as an implementation detail. It would be nice to be able to put this into a macro and not require the user to manually pull in the strum crates. Could a new release be made on crates.io so I can use this? Thanks! |
Hi @cosmicchipsocket and @billy1624, thanks for the push. Version |
Thanks! @cosmicchipsocket |
Motivation
Our team is developing a library which requires downstream end-user to derive
strum_macro::EnumIter
for their custom enum.However, the expanded codes from
strum_macro::EnumIter
looks something like this and failed to compile...This signature,
::strum::IntoEnumIterator
, implies our downstream end-user must add thestrum
dependency on their own.Hence, we want to find a way to re-export
strum
&strum_macros
in our library. And downstream end-user don't need to specify thestrum
dependency on their own.Proposed Solution
Adding an optional derive attribute
#[strum(crate_path = "some_crate::strum")]
, for example...Backward compatibility, if the derive attribute was not provided...
References
Similar feature was discussed on serde-rs/serde#1465. And
serde
provides a optional derive attribute to achieve it.