about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authoroxalica <oxalicc@pm.me>2022-08-07 04:48:52 +0800
committeroxalica <oxalicc@pm.me>2022-08-07 04:53:23 +0800
commit326ffee5b71e0113be20fc3b3b2aefbd4cd3b6d9 (patch)
treed2d7f49bd67b0ced5dbdc0426d0cba2a2ddae632 /lib
parent1a94193602e65c99344ba313c71d4298b0d4c0cc (diff)
downloadrust-326ffee5b71e0113be20fc3b3b2aefbd4cd3b6d9.tar.gz
rust-326ffee5b71e0113be20fc3b3b2aefbd4cd3b6d9.zip
Returns the old value for la_arena::ArenaMap::insert
Diffstat (limited to 'lib')
-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 3034e33a788..5f347e27450 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