aboutsummaryrefslogtreecommitdiff
path: root/lib/arena/src
diff options
context:
space:
mode:
Diffstat (limited to 'lib/arena/src')
-rw-r--r--lib/arena/src/lib.rs25
1 files changed, 24 insertions, 1 deletions
diff --git a/lib/arena/src/lib.rs b/lib/arena/src/lib.rs
index 230a50291..1720537cb 100644
--- a/lib/arena/src/lib.rs
+++ b/lib/arena/src/lib.rs
@@ -90,7 +90,7 @@ impl<T> Idx<T> {
90} 90}
91 91
92/// Yet another index-based arena. 92/// Yet another index-based arena.
93#[derive(Clone, PartialEq, Eq)] 93#[derive(Clone, PartialEq, Eq, Hash)]
94pub struct Arena<T> { 94pub struct Arena<T> {
95 data: Vec<T>, 95 data: Vec<T>,
96} 96}
@@ -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();