Skip to content

Commit

Permalink
impl BuildList for tuples of up to 12 elements
Browse files Browse the repository at this point in the history
  • Loading branch information
micahrj committed Aug 23, 2024
1 parent 67e874f commit a577964
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,46 @@ where
self.1.rebuild_list(cx, &mut second, &mut state.second);
}
}

impl<T> BuildList<T> for () {
type State = ();

fn build_list(self, _cx: &mut Context, _list: &mut impl Edit<T>) -> Self::State {
()
}

fn rebuild_list(self, _cx: &mut Context, _list: &mut impl Edit<T>, _state: &mut Self::State) {}
}

macro_rules! build_list_tuple {
($($index:tt $item:ident),*) => {
impl<$($item,)* T> BuildList<T> for ($($item,)*)
where
$($item: BuildItem<T>,)*
{
type State = ();

fn build_list(self, cx: &mut Context, list: &mut impl Edit<T>) -> Self::State {
$(list.push(self.$index.build_item(cx));)*
()
}

fn rebuild_list(self, cx: &mut Context, list: &mut impl Edit<T>, _state: &mut Self::State) {
$(self.$index.rebuild_item(cx, list.get_mut($index).unwrap());)*
}
}
}
}

build_list_tuple!(0 T0);
build_list_tuple!(0 T0, 1 T1);
build_list_tuple!(0 T0, 1 T1, 2 T2);
build_list_tuple!(0 T0, 1 T1, 2 T2, 3 T3);
build_list_tuple!(0 T0, 1 T1, 2 T2, 3 T3, 4 T4);
build_list_tuple!(0 T0, 1 T1, 2 T2, 3 T3, 4 T4, 5 T5);
build_list_tuple!(0 T0, 1 T1, 2 T2, 3 T3, 4 T4, 5 T5, 6 T6);
build_list_tuple!(0 T0, 1 T1, 2 T2, 3 T3, 4 T4, 5 T5, 6 T6, 7 T7);
build_list_tuple!(0 T0, 1 T1, 2 T2, 3 T3, 4 T4, 5 T5, 6 T6, 7 T7, 8 T8);
build_list_tuple!(0 T0, 1 T1, 2 T2, 3 T3, 4 T4, 5 T5, 6 T6, 7 T7, 8 T8, 9 T9);
build_list_tuple!(0 T0, 1 T1, 2 T2, 3 T3, 4 T4, 5 T5, 6 T6, 7 T7, 8 T8, 9 T9, 10 T10);
build_list_tuple!(0 T0, 1 T1, 2 T2, 3 T3, 4 T4, 5 T5, 6 T6, 7 T7, 8 T8, 9 T9, 10 T10, 11 T11);

0 comments on commit a577964

Please sign in to comment.