xilem icon indicating copy to clipboard operation
xilem copied to clipboard

Add #[derive(View)] for enums and nested structs

Open matthunz opened this issue 2 years ago • 1 comments

I think a derive macro for the view trait, especially on enums, would really benefit ergonomics. Views that return multiple types on a condition, such as an if block or match statement, could instead return an enum with View derived.

For example, for conditional views we could return a custom enum like:

#[derive(View)]
enum UserForm {
  Login(LoginView),
  SignUp(SignUpView)
}

matthunz avatar Jan 03 '23 04:01 matthunz

Sorry for the slow response. I like the idea to derive View for enums but am not so sure about structs. We already have implemented ViewSequence for Tuples. I don't see the benefit of implementing this for other product types. The other thing to consider is that we already have AnyView which can do the same thing. And since this would be more of a performance improvement for platforms like embedded, it not a priority right now.

xarvic avatar Mar 07 '23 19:03 xarvic