Closed anussel5559 closed 2 weeks ago
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: https://github.com/ccbrown/iocraft/pull/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.
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.
Released in 0.4.0. Thanks again!
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:
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.