diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/arena/src/lib.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/arena/src/lib.rs b/lib/arena/src/lib.rs index 230a50291..bce15c867 100644 --- a/lib/arena/src/lib.rs +++ b/lib/arena/src/lib.rs | |||
@@ -194,6 +194,29 @@ impl<T> Arena<T> { | |||
194 | self.data.iter().enumerate().map(|(idx, value)| (Idx::from_raw(RawIdx(idx as u32)), value)) | 194 | self.data.iter().enumerate().map(|(idx, value)| (Idx::from_raw(RawIdx(idx as u32)), value)) |
195 | } | 195 | } |
196 | 196 | ||
197 | /// Returns an iterator over the arena’s mutable elements. | ||
198 | /// | ||
199 | /// ``` | ||
200 | /// let mut arena = la_arena::Arena::new(); | ||
201 | /// let idx1 = arena.alloc(20); | ||
202 | /// | ||
203 | /// assert_eq!(arena[idx1], 20); | ||
204 | /// | ||
205 | /// let mut iterator = arena.iter_mut(); | ||
206 | /// *iterator.next().unwrap().1 = 10; | ||
207 | /// drop(iterator); | ||
208 | /// | ||
209 | /// assert_eq!(arena[idx1], 10); | ||
210 | /// ``` | ||
211 | pub fn iter_mut( | ||
212 | &mut self, | ||
213 | ) -> impl Iterator<Item = (Idx<T>, &mut T)> + ExactSizeIterator + DoubleEndedIterator { | ||
214 | self.data | ||
215 | .iter_mut() | ||
216 | .enumerate() | ||
217 | .map(|(idx, value)| (Idx::from_raw(RawIdx(idx as u32)), value)) | ||
218 | } | ||
219 | |||
197 | /// Reallocates the arena to make it take up as little space as possible. | 220 | /// Reallocates the arena to make it take up as little space as possible. |
198 | pub fn shrink_to_fit(&mut self) { | 221 | pub fn shrink_to_fit(&mut self) { |
199 | self.data.shrink_to_fit(); | 222 | self.data.shrink_to_fit(); |