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
AsRef
for enum
#219
Comments
Seems like a useful enhancement. Especially the simple case seems easy to implement where both variants have the same type. |
After I ran into this again, I thought I might as well start working on it. Will only implement the simple case where everything has the same type for now. I think it would make sense to allow #[derive(AsRef)]
#[as_ref(forward)] // or #[as_ref(Type)]
enum Enum {
NewType(Type),
Multiple(#[as_ref] Type, Other),
} I would probably mirror this to structs while keeping placing this information on the field valid: // current
#[derive(AsRef)]
struct OnField(#[as_ref(forward)] Field, Other);
// will also be valid
#[derive(AsRef)]
#[as_ref(forward)]
struct OnStruct(#[as_ref] Field, Other); I could also implement a check disallowing it on structs, but IMO there is little value gained by restricting item attributes to structs. |
I'm gonna write down some more thoughts: if no types are specified, or Without the use of With I'd be fine implementing either. We could also avoid this topic by disallowing |
This would require you to put the correct attributes on each enum variant, same as for the struct derive:
We would maybe need to be able to specify the actual type here, this would be necessary in case of forward when there are two different types that only share a subset of
AsRef
implementations.The text was updated successfully, but these errors were encountered: