-
Notifications
You must be signed in to change notification settings - Fork 25
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
Conditional derive #188
Comments
Hi! Technically there is nothing that limits us to implement it, it will just require some effort though. |
Is there a reason why you can't just let the user add separate |
Answered in #191 (comment) I copy answer here for other readers:
I guess I need to add an FAQ section |
Is there a short term fix that can be applied in the meantime? |
@LockedThread Which trait do you need? What it is possible is to implement a trait manually in terms of other traits. (if it's very repetitive, a macro rules can be used). |
Serde traits, enabled by feature. I wasn't able to use cfg_attr to enable them. However, I was able to make 2 modules and enable those based on the feature and then reexport the nutype's defined inside of them. Not a very clean solution, but it works. |
When implementing REST API clients, I usually derive
Serialize
andDefault
conditionally for tests, like so:This enables me to use
Default
andSerialize
in tests to easily and quickly instantiate mock responses, while at the same time keeping the prod binary smaller and prod compile times lower.Unfortunately conditional derive doesn't currently seem possible in nutype.
Would it be possible to enable nutype to do something similar? Like
Or maybe
Whatever makes the most sense. I am a complete noob when it comes to Rust macros, and proc macros especially, so no idea what the best solution would be.
This request is not super important, as it works just fine without the conditional derive, it would just be nice to have.
Actually now that I think about it, it would also be nice to have this for libraries wanting to conditionally derive on feature flags, not just on tests.
The text was updated successfully, but these errors were encountered: