1use self::private::Sealed;
2
3mod private {
4 pub trait Sealed {}
5
6 impl<T> Sealed for Vec<T> {}
7 impl<T> Sealed for &mut Vec<T> {}
8 impl<T> Sealed for &mut [T] {}
9 impl<T> Sealed for &[T] {}
10}
11pub trait IntoItems: Sealed {
12 type Elem;
13 type Items: Items<Elem = Self::Elem>;
14
15 fn into_items(self) -> Self::Items;
16}
17
18impl<T, I> IntoItems for I
19where
20 I: Items<Elem = T>,
21{
22 type Elem = T;
23 type Items = I;
24
25 fn into_items(self) -> Self::Items {
26 self
27 }
28}
29
30impl<'a, T> IntoItems for &'a mut Vec<T>
31where
32 T: Send + Sync,
33{
34 type Elem = &'a mut T;
35 type Items = &'a mut [T];
36
37 fn into_items(self) -> Self::Items {
38 self
39 }
40}
41
42#[allow(clippy::len_without_is_empty)]
44pub trait Items: Sized + IntoIterator<Item = Self::Elem> + Send + Sealed {
45 type Elem: Send + Sync;
46
47 fn len(&self) -> usize;
48
49 fn split_at(self, idx: usize) -> (Self, Self);
50}
51
52impl<T> Items for Vec<T>
53where
54 T: Send + Sync,
55{
56 type Elem = T;
57
58 fn len(&self) -> usize {
59 Vec::len(self)
60 }
61
62 fn split_at(mut self, at: usize) -> (Self, Self) {
63 let b = self.split_off(at);
64
65 (self, b)
66 }
67}
68
69impl<'a, T> Items for &'a mut [T]
70where
71 T: Send + Sync,
72{
73 type Elem = &'a mut T;
74
75 fn len(&self) -> usize {
76 <[T]>::len(self)
77 }
78
79 fn split_at(self, at: usize) -> (Self, Self) {
80 let (a, b) = self.split_at_mut(at);
81
82 (a, b)
83 }
84}
85
86impl<'a, T> Items for &'a [T]
87where
88 T: Send + Sync,
89{
90 type Elem = &'a T;
91
92 fn len(&self) -> usize {
93 <[T]>::len(self)
94 }
95
96 fn split_at(self, at: usize) -> (Self, Self) {
97 let (a, b) = self.split_at(at);
98
99 (a, b)
100 }
101}
102