Skip to content
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

It seems like the component macro doesn't account for generic type arguments well #32

Closed
anussel5559 opened this issue Oct 30, 2024 · 3 comments
Labels
bug Something isn't working enhancement New feature or request

Comments

@anussel5559
Copy link

anussel5559 commented Oct 30, 2024

Trying to use the component macro on a component that takes in a props struct with a generic type argument doesn't work as I might expect:
CleanShot 2024-10-30 at 17 19 59@2x
CleanShot 2024-10-30 at 17 23 13@2x

It's possible I'm missing something, but when I remove the macro, the resulting function correctly correlates the type definition to the struct in its arguments.

@ccbrown
Copy link
Owner

ccbrown commented Oct 31, 2024

Thanks for the report. You're not missing anything. This just isn't a use-case I had considered. It is one I'd like to support though.

It's actually possible with the current release to define generic components without using the #[component] macro, and the element! macro supports generic type parameters just fine.

Adding/fixing support for type and const parameters with the #[component] macro is easy enough: #33

I've just merged that and assuming I don't find any issues it'll go out with the next release. Until then, you can try it via:

iocraft = { git = "https://github.com/ccbrown/iocraft.git", rev = "8b6d0141eeb96fad92482f3ec3420b136812e09e" }

Please let me know if that meets your needs.

There is a caveat: Whether using the #[component] macro or not, the type parameters must be 'static. So you'll need to declare your function like fn ListBox<T: 'static>. I don't see any obvious way around that unfortunately. I'd be interested to hear if that gets in the way of your or anyone else's use-case.

@ccbrown ccbrown added bug Something isn't working enhancement New feature or request labels Oct 31, 2024
@anussel5559
Copy link
Author

oh awesome! thanks for the quick PR.

I grabbed that revision and it definitely meets my needs! the 'static requirement isn't a blocker for me.

@ccbrown
Copy link
Owner

ccbrown commented Nov 1, 2024

Released in 0.4.0. Thanks again!

@ccbrown ccbrown closed this as completed Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants