-
-
Notifications
You must be signed in to change notification settings - Fork 599
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
Support for impl Trait
inside #[component]
params
#2274
Comments
The props are built into a struct with a typed builder, since Rust doesn't support named/keyword arguments for functions. As a result, this fn Foo<T, IV1, IVF1, IV2, IVF2, IV3, IVF3, IV4, IVF4>(
v1: IVF1,
v2: IVF2,
v3: IVF3,
v4: IVF4,
) -> impl IntoView
where
IV1: IntoView,
IV2: IntoView,
IV3: IntoView,
IV4: IntoView,
IVF1: Fn(T) -> IV1 + 'static,
IVF2: Fn(T) -> IV2 + 'static,
IVF3: Fn(T) -> IV3 + 'static,
IVF4: Fn(T) -> IV4 + 'static, can relatively easily be rewritten to struct FooProps<T, IV1, IVF1, IV2, IVF2, IV3, IVF3, IV4, IVF4> {
v1: IVF1,
v2: IVF2,
v3: IVF3,
v4: IVF4,
}
where
IV1: IntoView,
IV2: IntoView,
IV3: IntoView,
IV4: IntoView,
IVF1: Fn(T) -> IV1 + 'static,
IVF2: Fn(T) -> IV2 + 'static,
IVF3: Fn(T) -> IV3 + 'static,
IVF4: Fn(T) -> IV4 + 'static, because there is a 1:1 relationship between the generics, parameters/field names, and It is much harder to do this with fn Foo<T, IV1, IV2, IV3, IV4>(
v1: impl Fn(T) -> IV1,
v2: impl Fn(T) -> IV2,
v3: impl Fn(T) -> IV3,
v4: impl Fn(T) -> IV4,
) -> impl IntoView
where
IV1: IntoView,
IV2: IntoView,
IV3: IntoView,
IV4: IntoView,
{...} because there is no support for " Hence why this has not been added. Is it something you might be interested in working on? |
On second thought, I don't think it's particularly worth the additional complexity and compile time performance. |
This seems... not that hard? Just generate an extra generic name for each |
@MingweiSamuel Go for a PR! |
Easiest strategy is to pre-process the signature to remove Ok to just add that^? (Ill optimize a bit. Could also generate more descriptive generic param names). Could even feature flag it with one line if wanted |
…c type params, fix leptos-rs#2274 Book needs to be updated to remove this line: https://github.com/leptos-rs/book/blob/35c380ffc8f7d2e50ef21db97943138b3dba2728/src/view/03_components.md?plain=1#L233
…c type params, fix leptos-rs#2274 Book needs to be updated to remove this line: https://github.com/leptos-rs/book/blob/35c380ffc8f7d2e50ef21db97943138b3dba2728/src/view/03_components.md?plain=1#L233
…c type params, fix leptos-rs#2274 Book needs to be updated to remove this line: https://github.com/leptos-rs/book/blob/35c380ffc8f7d2e50ef21db97943138b3dba2728/src/view/03_components.md?plain=1#L233
…c type params, fix leptos-rs#2274 Book needs to be updated to remove this line: https://github.com/leptos-rs/book/blob/35c380ffc8f7d2e50ef21db97943138b3dba2728/src/view/03_components.md?plain=1#L233
…c type params, fix leptos-rs#2274 Book needs to be updated to remove this line: https://github.com/leptos-rs/book/blob/35c380ffc8f7d2e50ef21db97943138b3dba2728/src/view/03_components.md?plain=1#L233
…c type params, fix leptos-rs#2274 Book needs to be updated to remove this line: https://github.com/leptos-rs/book/blob/35c380ffc8f7d2e50ef21db97943138b3dba2728/src/view/03_components.md?plain=1#L233
…c type params, fix leptos-rs#2274 Book needs to be updated to remove this line: https://github.com/leptos-rs/book/blob/35c380ffc8f7d2e50ef21db97943138b3dba2728/src/view/03_components.md?plain=1#L233
…c type params, fix leptos-rs#2274 Book needs to be updated to remove this line: https://github.com/leptos-rs/book/blob/35c380ffc8f7d2e50ef21db97943138b3dba2728/src/view/03_components.md?plain=1#L233
…c type params, fix #2274 (#2599) Book needs to be updated to remove this line: https://github.com/leptos-rs/book/blob/35c380ffc8f7d2e50ef21db97943138b3dba2728/src/view/03_components.md?plain=1#L233
Is your feature request related to a problem? Please describe.
It's sort of annoying having to specify generic args on a component that has a lot of views.
e.g.
Describe the solution you'd like
I would like to write my components like this:
or even
if I'm feeling particularly lazy.
Describe alternatives you've considered
The alternatives are just continue using the standard way of doing it.
The text was updated successfully, but these errors were encountered: