Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'lib/la-arena/src/map.rs')
-rw-r--r--lib/la-arena/src/map.rs7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/la-arena/src/map.rs b/lib/la-arena/src/map.rs
index 3034e33a78..5f347e2745 100644
--- a/lib/la-arena/src/map.rs
+++ b/lib/la-arena/src/map.rs
@@ -49,11 +49,14 @@ impl<T, V> ArenaMap<Idx<T>, V> {
}
/// Inserts a value associated with a given arena index into the map.
- pub fn insert(&mut self, idx: Idx<T>, t: V) {
+ ///
+ /// If the map did not have this index present, None is returned.
+ /// Otherwise, the value is updated, and the old value is returned.
+ pub fn insert(&mut self, idx: Idx<T>, t: V) -> Option<V> {
let idx = Self::to_idx(idx);
self.v.resize_with((idx + 1).max(self.v.len()), || None);
- self.v[idx] = Some(t);
+ self.v[idx].replace(t)
}
/// Returns a reference to the value associated with the provided index