From b8fe6bf0f5d8099c93f9484d60def1e508b18ce3 Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Tue, 5 Dec 2017 10:01:35 -0800 Subject: [PATCH] Add a MapCursor::value_mut() method. It's ok to alter a value stored in a map, but not the keys. --- lib/cretonne/src/bforest/map.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/cretonne/src/bforest/map.rs b/lib/cretonne/src/bforest/map.rs index 3c5fe7fb9e..5aa19bceda 100644 --- a/lib/cretonne/src/bforest/map.rs +++ b/lib/cretonne/src/bforest/map.rs @@ -306,6 +306,13 @@ where }) } + /// Get a mutable reference to the current value, or `None` if the cursor is at the end. + pub fn value_mut(&mut self) -> Option<&mut V> { + self.path.leaf_pos().and_then(move |(node, entry)| { + self.pool[node].unwrap_leaf_mut().1.get_mut(entry) + }) + } + /// Move this cursor to `key`. /// /// If `key` is in the map, place the cursor at `key` and return the corresponding value.