-
Notifications
You must be signed in to change notification settings - Fork 58
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
derive macros for ToRef and ToMut? #224
Comments
Just checking what you're asking for by using a concrete example Given struct S {
a: u64,
b: bool
}
let s = Struct { a: 5, b: false};
let s_ref = &s; You want to be able to (something like) this: let s_ref_repr: HList![ &u64, &bool ] = s_ref.into_generic_ref(); ? Some follow up questions:
|
Yes, that's exactly what I'm looking for
I have a large crate that was originally littered with structs like:
I think in total there were about 8 structs like this and each one has the "same" 21 fields. About half have associated lifetimes and are constructed from references to others. Every time anyone wants to add a new field, they have to go through and update all of them and then they have to go through and update every place where each of the fields is addressed in turn doing the exact same thing. I noticed I could reduce boilerplate with GATs and marker types:
Then for the conversions between them that didn't involve references, I could use frunk (by deriving
But I still ended up with three instances of expressing all the fields in turn rather than a single
(Preferrable):
than if it's defined as: (Less preferrable):
Thanks so much! |
FYI, just opened https://github.com/davidspies/frunk_utils |
Thanks @dspyz-matician I think what you want makes sense and would make a good addition to the lib. Regarding introducing a new BTW, if you're willing to give this a go, by all means, please go ahead! |
If I have an
&'a T
whereT
implementsGeneric
, it seems like I ought to be able to get a<T::Repr as ToRef<'a>>::Output
from it, but there isn't any safe way to do that generically. It would be nice to have a derive macro which does thisThe text was updated successfully, but these errors were encountered: