diff options
| author | Mica White <botahamec@outlook.com> | 2026-05-21 18:50:06 -0400 |
|---|---|---|
| committer | Mica White <botahamec@outlook.com> | 2026-05-21 18:50:06 -0400 |
| commit | 868329539613b40b48565c6bf11fd4920beaacee (patch) | |
| tree | 481ab2e75eb6d5d4d7c34cdebff8d036e4d34f31 /src/lib.rs | |
| parent | ea98969d350109487a42a01f0e5ef08afa4b01ac (diff) | |
Diffstat (limited to 'src/lib.rs')
| -rw-r--r-- | src/lib.rs | 50 |
1 files changed, 41 insertions, 9 deletions
@@ -3,6 +3,8 @@ use varihappy_macros::{ type_to_field_access, }; +pub use varihappy_macros::array_tuple; + pub trait Tuple { const LEN: usize; @@ -29,14 +31,21 @@ pub trait Tuple1: Tuple { fn into_rest(self) -> Self::Rest; } -pub trait ArrayTupleOrEmpty<T>: Tuple {} +pub trait ArrayTuple<T>: Tuple { + fn fill(item: T) -> Self + where + Self: Sized, + T: Copy; +} -pub trait ArrayTuple: Tuple { +pub trait NonEmptyArrayTuple: Tuple { type Item; -} -impl<T> ArrayTupleOrEmpty<T> for () {} -impl<I, T: ArrayTuple<Item = I>> ArrayTupleOrEmpty<T> for T {} + fn fill(item: Self::Item) -> Self + where + Self: Sized, + Self::Item: Copy; +} impl Tuple for () { type AsRef<'a> @@ -57,6 +66,25 @@ impl Tuple for () { fn rev(self) -> Self::Reversed {} } +impl<T> ArrayTuple<T> for () { + fn fill(_item: T) -> Self + where + Self: Sized, + T: Copy, + { + } +} + +impl<I, T: NonEmptyArrayTuple<Item = I>> ArrayTuple<I> for T { + fn fill(item: I) -> Self + where + Self: Sized, + I: Copy, + { + <Self as NonEmptyArrayTuple>::fill(item) + } +} + macro_rules! tuple_apply { (($($letter: ident,)*), $other: ident) => { $other!(($($letter,)*)) @@ -192,16 +220,20 @@ macro_rules! tuple_trait { }; } -macro_rules! t { - ($_t:tt) => { - T +macro_rules! replace { + ($_t:tt, $new: tt) => { + $new }; } macro_rules! impl_array_tuple_inner { (($($letter: ident,)*)) => { - impl<T> ArrayTuple for ($(t!($letter),)*) { + impl<T> NonEmptyArrayTuple for ($(replace!($letter, T),)*) { type Item = T; + + fn fill(item: Self::Item) -> Self where T: Copy { + ($(replace!($letter, item),)*) + } } }; } |
