-
Notifications
You must be signed in to change notification settings - Fork 8
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
MultiIndexMap should derive Debug, when inner type derives Debug #26
Comments
Hey! Yeah indeed I do want to implement this but currently it only seems possible with nightly and the specialization feature. It could be possible to add an optional feature that works on nightly, I'll have a look at how much work this would be |
Sounds great! Let me know, if there is anything I can help you with! |
I had a go at an initial implementation on https://github.com/lun3x/multi_index_map/tree/trivial_bounds |
One thing you were probably missing was adding the debug guards for the other fields of the original elements. Let me know, if I missed something! |
It would be great to have the same to Serialize\Deserialize if possible. |
Yeah absolutely agree, I've merged the trivial_bounds feature to master. Now we can add some more derived impls that rely on this, Clone would be an easy one to start with. Serialize/Deserialize is also possible, although I suppose this would add a requirement on serde, so I guess then we need a new feature, we can just call it |
This is what I was thinking. I will hopefully be able to work on this next week if that is alright with you! |
@lun3x I wanted to discuss following problem with you: Currently we use the Adding #[derive(...)] to types is apparently possible with |
Yeah I agree, it is quite difficult to reason about exactly how these traits get added right now. I think it might be possible to refactor things a bit to move this section of the generation into a separate module, but if we can just use Derive and Clone that would be much nicer. The impls crate looks nice, although on first glance it seems like it would be difficult to use the generated So you mean instead of a Derive macro, potentially we could use a raw proc_macro_attribute? Yeah I'm not opposed to that, obviously it would be a breaking change, but if we keep the interface similar it shouldn't be a large code change for end users. |
So I experimented a bit. It is possible to use e.g. So the way I see it is, we could continue to implement all traits manually within the macro - that means writing out debug, clone, serialize, etc. which is more difficult to maintain, or we could introduce something like the following syntax:
Here the new attribute Do you have any other ideas on how to proceed? While the current solution is not a problem for Clone and Debug, implementing serdes (de-)serialize methods gets ugly quite quickly... |
Hey so I've had a bit of a look around the rust ecosystem to try to find out what the accepted approach is here. soa_derive uses something similar, also with support for cfg_attr:
rkyv also uses roughly this pattern:
I think this is fine, obviously a bit verbose, but that seems pretty standard. I would suggest we go with the following syntax, and potentially later add support for cfg_attr:
|
Awesome! Looks good to me. |
Awesome no worries, I've not worked on this yet so that would be great, thanks a lot! |
serde derive for generated struct, both Serialize and Deserialize, still not work |
Thank you so much for your work @lun3x! |
When the struct, where the derive macro
#[derive(MultiIndexMap)
is added, also derives theDebug
trait, the generated MultiIndexMap should also derive theDebug
trait.As far as I can tell, this is currently not possible, but could be when specialization is stabilized:
dtolnay/syn#77 (comment)
But maybe you have another idea how to implement this feature already!
The text was updated successfully, but these errors were encountered: