1#![no_std]
2
3#[tuplities_derive::impl_split]
24pub trait TupleSplit<Idx: typenum::Unsigned> {
25 type Left;
27
28 type Right;
30
31 fn split(self) -> (Self::Left, Self::Right);
33}
34
35#[cfg(test)]
36mod tests {
37 use super::TupleSplit;
38 use typenum::{U0, U1, U2, U3};
39
40 #[test]
41 fn test_split_at_zero() {
42 let tuple = (1, 2, 3);
43 let (left, right) = TupleSplit::<U0>::split(tuple);
44 assert_eq!(left, ());
45 assert_eq!(right, (1, 2, 3));
46 }
47
48 #[test]
49 fn test_split_at_middle() {
50 let tuple = (1, 2, 3, 4);
51 let (left, right) = TupleSplit::<U2>::split(tuple);
52 assert_eq!(left, (1, 2));
53 assert_eq!(right, (3, 4));
54 }
55
56 #[test]
57 fn test_split_at_end() {
58 let tuple = (1, 2, 3);
59 let (left, right) = TupleSplit::<U3>::split(tuple);
60 assert_eq!(left, (1, 2, 3));
61 assert_eq!(right, ());
62 }
63
64 #[test]
65 fn test_split_empty_tuple() {
66 let tuple = ();
67 let (left, right) = TupleSplit::<U0>::split(tuple);
68 assert_eq!(left, ());
69 assert_eq!(right, ());
70 }
71
72 #[test]
73 fn test_split_single_element_at_zero() {
74 let tuple = (42,);
75 let (left, right) = TupleSplit::<U0>::split(tuple);
76 assert_eq!(left, ());
77 assert_eq!(right, (42,));
78 }
79
80 #[test]
81 fn test_split_single_element_at_one() {
82 let tuple = (42,);
83 let (left, right) = TupleSplit::<U1>::split(tuple);
84 assert_eq!(left, (42,));
85 assert_eq!(right, ());
86 }
87
88 #[test]
89 fn test_split_two_elements_at_zero() {
90 let tuple = (1, 2);
91 let (left, right) = TupleSplit::<U0>::split(tuple);
92 assert_eq!(left, ());
93 assert_eq!(right, (1, 2));
94 }
95
96 #[test]
97 fn test_split_two_elements_at_one() {
98 let tuple = (1, 2);
99 let (left, right) = TupleSplit::<U1>::split(tuple);
100 assert_eq!(left, (1,));
101 assert_eq!(right, (2,));
102 }
103
104 #[test]
105 fn test_split_two_elements_at_two() {
106 let tuple = (1, 2);
107 let (left, right) = TupleSplit::<U2>::split(tuple);
108 assert_eq!(left, (1, 2));
109 assert_eq!(right, ());
110 }
111}