1use crate::SingleItemStorage;
2#[cfg(feature = "alloc")]
3use alloc::vec::Vec;
4
5pub trait GetMut {
7 type Error;
9 type Input;
11 type Output<'output>
13 where
14 Self: 'output;
15
16 fn get_mut(&mut self, input: Self::Input) -> Result<Self::Output<'_>, Self::Error>;
18}
19
20impl<T> GetMut for &mut T
21where
22 T: GetMut,
23{
24 type Error = T::Error;
25 type Input = T::Input;
26 type Output<'output>
27 = T::Output<'output>
28 where
29 Self: 'output;
30
31 #[inline]
32 fn get_mut(&mut self, input: Self::Input) -> Result<Self::Output<'_>, Self::Error> {
33 (*self).get_mut(input)
34 }
35}
36
37impl<T> GetMut for SingleItemStorage<T> {
42 type Error = crate::Error;
43 type Input = usize;
44 type Output<'output>
45 = &'output mut T
46 where
47 Self: 'output;
48
49 #[inline]
50 fn get_mut(&mut self, input: Self::Input) -> Result<Self::Output<'_>, Self::Error> {
51 _get_mut!(self.as_mut(), input)
52 }
53}
54
55impl<T, const N: usize> GetMut for [T; N] {
60 type Error = crate::Error;
61 type Input = usize;
62 type Output<'output>
63 = &'output mut T
64 where
65 Self: 'output;
66
67 #[inline]
68 fn get_mut(&mut self, input: Self::Input) -> Result<Self::Output<'_>, Self::Error> {
69 _get_mut!(self.as_mut(), input)
70 }
71}
72
73impl<T> GetMut for &'_ mut [T] {
78 type Error = crate::Error;
79 type Input = usize;
80 type Output<'output>
81 = &'output mut T
82 where
83 Self: 'output;
84
85 #[inline]
86 fn get_mut(&mut self, input: Self::Input) -> Result<Self::Output<'_>, Self::Error> {
87 _get_mut!(self.as_mut(), input)
88 }
89}
90
91#[cfg(feature = "alloc")]
96impl<T> GetMut for Vec<T> {
97 type Error = crate::Error;
98 type Input = usize;
99 type Output<'output>
100 = &'output mut T
101 where
102 Self: 'output;
103
104 #[inline]
105 fn get_mut(&mut self, input: Self::Input) -> Result<Self::Output<'_>, Self::Error> {
106 _get_mut!(self.as_mut_slice(), input)
107 }
108}
109
110#[cfg(feature = "arrayvec")]
115impl<T, const N: usize> GetMut for arrayvec::ArrayVec<T, N> {
116 type Error = crate::Error;
117 type Input = usize;
118 type Output<'output>
119 = &'output mut T
120 where
121 Self: 'output;
122
123 #[inline]
124 fn get_mut(&mut self, input: Self::Input) -> Result<Self::Output<'_>, Self::Error> {
125 _get_mut!(self.as_mut(), input)
126 }
127}
128
129#[cfg(feature = "smallvec")]
134impl<A> GetMut for smallvec::SmallVec<A>
135where
136 A: smallvec::Array,
137{
138 type Error = crate::Error;
139 type Input = usize;
140 type Output<'output>
141 = &'output mut A::Item
142 where
143 Self: 'output;
144
145 #[inline]
146 fn get_mut(&mut self, input: Self::Input) -> Result<Self::Output<'_>, Self::Error> {
147 _get_mut!(self.as_mut(), input)
148 }
149}
150
151#[cfg(feature = "tinyvec")]
156impl<A> GetMut for tinyvec::ArrayVec<A>
157where
158 A: tinyvec::Array,
159{
160 type Error = crate::Error;
161 type Input = usize;
162 type Output<'output>
163 = &'output mut A::Item
164 where
165 Self: 'output;
166
167 #[inline]
168 fn get_mut(&mut self, input: Self::Input) -> Result<Self::Output<'_>, Self::Error> {
169 _get_mut!(self.as_mut(), input)
170 }
171}
172
173#[cfg(all(feature = "alloc", feature = "tinyvec"))]
178impl<A> GetMut for tinyvec::TinyVec<A>
179where
180 A: tinyvec::Array,
181 A::Item: Default,
182{
183 type Error = crate::Error;
184 type Input = usize;
185 type Output<'output>
186 = &'output mut A::Item
187 where
188 Self: 'output;
189
190 #[inline]
191 fn get_mut(&mut self, input: Self::Input) -> Result<Self::Output<'_>, Self::Error> {
192 _get_mut!(self.as_mut(), input)
193 }
194}