cl_aux/traits/
remove.rs

1#[cfg(feature = "alloc")]
2use alloc::vec::Vec;
3
4/// See [`Remove::remove`] for more information.
5pub trait Remove {
6  /// Error
7  type Error;
8  /// Input
9  type Input;
10  /// Output
11  type Output;
12
13  /// Removes an element referenced by `Input`.
14  fn remove(&mut self, input: Self::Input) -> Result<Self::Output, Self::Error>;
15}
16
17impl<T> Remove for &mut T
18where
19  T: Remove,
20{
21  type Error = T::Error;
22  type Input = T::Input;
23  type Output = T::Output;
24
25  #[inline]
26  fn remove(&mut self, input: Self::Input) -> Result<Self::Output, Self::Error> {
27    (*self).remove(input)
28  }
29}
30
31/// ```rust
32/// let mut structure = cl_aux::doc_tests::vec();
33/// cl_aux::Remove::remove(&mut structure, 0);
34/// assert_eq!(structure.get(0), Some(&2));
35/// ```
36#[cfg(feature = "alloc")]
37impl<T> Remove for Vec<T> {
38  type Error = crate::Error;
39  type Input = usize;
40  type Output = T;
41
42  #[inline]
43  fn remove(&mut self, input: Self::Input) -> Result<Self::Output, Self::Error> {
44    _check_indcs!(self, input);
45    Ok(self.remove(input))
46  }
47}
48
49/// ```rust
50/// let mut structure = cl_aux::doc_tests::array_vec();
51/// cl_aux::Remove::remove(&mut structure, 0);
52/// assert_eq!(structure.get(0), Some(&2));
53/// ```
54#[cfg(feature = "arrayvec")]
55impl<T, const N: usize> Remove for arrayvec::ArrayVec<T, N> {
56  type Error = crate::Error;
57  type Input = usize;
58  type Output = T;
59
60  #[inline]
61  fn remove(&mut self, input: Self::Input) -> Result<Self::Output, Self::Error> {
62    _check_indcs!(self, input);
63    Ok(self.remove(input))
64  }
65}
66
67/// ```rust
68/// let mut structure = cl_aux::doc_tests::small_vec();
69/// cl_aux::Remove::remove(&mut structure, 0);
70/// assert_eq!(structure.get(0), Some(&2));
71/// ```
72#[cfg(feature = "smallvec")]
73impl<A> Remove for smallvec::SmallVec<A>
74where
75  A: smallvec::Array,
76{
77  type Error = crate::Error;
78  type Input = usize;
79  type Output = A::Item;
80
81  #[inline]
82  fn remove(&mut self, input: Self::Input) -> Result<Self::Output, Self::Error> {
83    _check_indcs!(self, input);
84    Ok(self.remove(input))
85  }
86}
87
88/// ```rust
89/// let mut structure = cl_aux::doc_tests::tiny_vec_array_vec();
90/// cl_aux::Remove::remove(&mut structure, 0);
91/// assert_eq!(structure.get(0), Some(&2));
92/// ```
93#[cfg(feature = "tinyvec")]
94impl<A> Remove for tinyvec::ArrayVec<A>
95where
96  A: tinyvec::Array,
97  A::Item: Default,
98{
99  type Error = crate::Error;
100  type Input = usize;
101  type Output = A::Item;
102
103  #[inline]
104  fn remove(&mut self, input: Self::Input) -> Result<Self::Output, Self::Error> {
105    _check_indcs!(self, input);
106    Ok(self.remove(input))
107  }
108}
109
110/// ```rust
111/// let mut structure = cl_aux::doc_tests::tiny_vec_tiny_vec();
112/// cl_aux::Remove::remove(&mut structure, 0);
113/// assert_eq!(structure.get(0), Some(&2));
114/// ```
115#[cfg(all(feature = "alloc", feature = "tinyvec"))]
116impl<A> Remove for tinyvec::TinyVec<A>
117where
118  A: tinyvec::Array,
119  A::Item: Default,
120{
121  type Error = crate::Error;
122  type Input = usize;
123  type Output = A::Item;
124
125  #[inline]
126  fn remove(&mut self, input: Self::Input) -> Result<Self::Output, Self::Error> {
127    _check_indcs!(self, input);
128    Ok(self.remove(input))
129  }
130}