diff options
| author | Lukas Wirth <lukastw97@gmail.com> | 2022-09-02 16:57:31 +0200 |
|---|---|---|
| committer | Lukas Wirth <lukastw97@gmail.com> | 2022-09-02 17:02:12 +0200 |
| commit | 8828049b2398b0df3bfc76d06bcf5154cdbe536a (patch) | |
| tree | 1ab88cda6240aab7f704bb22aeba0c7aceb3cf6f /lib | |
| parent | 2bb6635a852aefe4f1151352f0b11e3a9e2f5b6d (diff) | |
| download | rust-8828049b2398b0df3bfc76d06bcf5154cdbe536a.tar.gz rust-8828049b2398b0df3bfc76d06bcf5154cdbe536a.zip | |
Lift out the module scope into a field in the Resolver
A Resolver *always* has a module scope at the end of its scope stack, instead of encoding this as an invariant we can just lift this scope out into a field, allowing us to skip going through the scope vec indirection entirely.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/la-arena/src/lib.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/la-arena/src/lib.rs b/lib/la-arena/src/lib.rs index 50e8d06b660..ccaaf399176 100644 --- a/lib/la-arena/src/lib.rs +++ b/lib/la-arena/src/lib.rs @@ -322,6 +322,43 @@ impl<T> Arena<T> { .map(|(idx, value)| (Idx::from_raw(RawIdx(idx as u32)), value)) } + /// Returns an iterator over the arena’s values. + /// + /// ``` + /// let mut arena = la_arena::Arena::new(); + /// let idx1 = arena.alloc(20); + /// let idx2 = arena.alloc(40); + /// let idx3 = arena.alloc(60); + /// + /// let mut iterator = arena.values(); + /// assert_eq!(iterator.next(), Some(&20)); + /// assert_eq!(iterator.next(), Some(&40)); + /// assert_eq!(iterator.next(), Some(&60)); + /// ``` + pub fn values(&mut self) -> impl Iterator<Item = &T> + ExactSizeIterator + DoubleEndedIterator { + self.data.iter() + } + + /// Returns an iterator over the arena’s mutable values. + /// + /// ``` + /// let mut arena = la_arena::Arena::new(); + /// let idx1 = arena.alloc(20); + /// + /// assert_eq!(arena[idx1], 20); + /// + /// let mut iterator = arena.values_mut(); + /// *iterator.next().unwrap() = 10; + /// drop(iterator); + /// + /// assert_eq!(arena[idx1], 10); + /// ``` + pub fn values_mut( + &mut self, + ) -> impl Iterator<Item = &mut T> + ExactSizeIterator + DoubleEndedIterator { + self.data.iter_mut() + } + /// Reallocates the arena to make it take up as little space as possible. pub fn shrink_to_fit(&mut self) { self.data.shrink_to_fit(); |
