spinoso_array/array/tinyvec/
impls.rs1use core::ops::{Deref, DerefMut, Index, IndexMut};
2use core::slice::SliceIndex;
3
4use super::TinyArray;
5
6impl<T> AsRef<[T]> for TinyArray<T>
7where
8 T: Default,
9{
10 #[inline]
11 fn as_ref(&self) -> &[T] {
12 self.0.as_ref()
13 }
14}
15
16impl<T> AsMut<[T]> for TinyArray<T>
17where
18 T: Default,
19{
20 #[inline]
21 fn as_mut(&mut self) -> &mut [T] {
22 self.0.as_mut()
23 }
24}
25
26impl<T> Deref for TinyArray<T>
27where
28 T: Default,
29{
30 type Target = [T];
31
32 #[inline]
33 fn deref(&self) -> &Self::Target {
34 &self.0
35 }
36}
37
38impl<T> DerefMut for TinyArray<T>
39where
40 T: Default,
41{
42 #[inline]
43 fn deref_mut(&mut self) -> &mut Self::Target {
44 &mut self.0
45 }
46}
47
48impl<T> Extend<T> for TinyArray<T>
49where
50 T: Default,
51{
52 #[inline]
53 fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I) {
54 self.0.extend(iter);
55 }
56}
57
58impl<'a, T> Extend<&'a T> for TinyArray<T>
59where
60 T: 'a + Clone + Default,
61{
62 #[inline]
63 fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I) {
64 self.0.extend(iter.into_iter().cloned());
65 }
66}
67
68impl<T, I> Index<I> for TinyArray<T>
69where
70 I: SliceIndex<[T]>,
71 T: Default,
72{
73 type Output = I::Output;
74
75 #[inline]
76 fn index(&self, index: I) -> &I::Output {
77 &self.0[index]
78 }
79}
80
81impl<T, I> IndexMut<I> for TinyArray<T>
82where
83 I: SliceIndex<[T]>,
84 T: Default,
85{
86 #[inline]
87 fn index_mut(&mut self, index: I) -> &mut I::Output {
88 &mut self.0[index]
89 }
90}