ccbrown / iocraft

A Rust crate for beautiful, artisanally crafted CLIs, TUIs, and text-based IO.
https://crates.io/crates/iocraft
Apache License 2.0
339 stars 5 forks source link

feat: support generic type parameters for component macro #33

Closed ccbrown closed 2 weeks ago

ccbrown commented 2 weeks ago

What It Does

Adds support for generic type and const parameters for the component macro.


 #[derive(Props)]
 struct MyGenericProps<T, const U: usize> {
     foo: [T; U],
 }

 #[component]
 fn MyComponentWithGenericProps<T: 'static, const U: usize>(
     _props: &mut MyGenericProps<T, U>,
 ) -> impl Into<AnyElement<'static>> {
     element!(Box)
 }

 #[component]
 fn MyComponentWithGenericPropsWhereClause<T, const U: usize>(
     _props: &mut MyGenericProps<T, U>,
 ) -> impl Into<AnyElement<'static>>
 where
     T: 'static,
 {
     element!(Box)
 }

Related Issues

https://github.com/ccbrown/iocraft/issues/32

codecov[bot] commented 2 weeks ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 91.14%. Comparing base (e412e99) to head (5a90fc3). Report is 1 commits behind head on main.

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/ccbrown/iocraft/pull/33/graphs/tree.svg?width=650&height=150&src=pr&token=NTFy59V3VP&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Chris)](https://app.codecov.io/gh/ccbrown/iocraft/pull/33?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Chris) ```diff @@ Coverage Diff @@ ## main #33 +/- ## ========================================== + Coverage 90.99% 91.14% +0.15% ========================================== Files 23 23 Lines 3386 3445 +59 Branches 3386 3445 +59 ========================================== + Hits 3081 3140 +59 Misses 238 238 Partials 67 67 ``` | [Files with missing lines](https://app.codecov.io/gh/ccbrown/iocraft/pull/33?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Chris) | Coverage Δ | | |---|---|---| | [packages/iocraft-macros/src/lib.rs](https://app.codecov.io/gh/ccbrown/iocraft/pull/33?src=pr&el=tree&filepath=packages%2Fiocraft-macros%2Fsrc%2Flib.rs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Chris#diff-cGFja2FnZXMvaW9jcmFmdC1tYWNyb3Mvc3JjL2xpYi5ycw==) | `95.72% <100.00%> (+0.50%)` | :arrow_up: | [![Impacted file tree graph](https://app.codecov.io/gh/ccbrown/iocraft/pull/33/graphs/tree.svg?width=650&height=150&src=pr&token=NTFy59V3VP&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Chris)](https://app.codecov.io/gh/ccbrown/iocraft/pull/33?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Chris)