Skip to content

Commit 97a806c

Browse files
authored
feat: add value_mut function (#155)
1 parent 0c1b7c0 commit 97a806c

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/kbucket/bucket.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ where
653653
///
654654
/// Returns `None` if the given key does not refer to an node in the
655655
/// bucket.
656-
fn get_mut(&mut self, key: &Key<TNodeId>) -> Option<&mut Node<TNodeId, TVal>> {
656+
pub fn get_mut(&mut self, key: &Key<TNodeId>) -> Option<&mut Node<TNodeId, TVal>> {
657657
self.nodes.iter_mut().find(move |p| &p.key == key)
658658
}
659659

src/kbucket/entry.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,16 @@ where
128128
.value
129129
}
130130

131+
/// Returns mutable access value associated with the key.
132+
pub fn value_mut(&mut self) -> &mut TVal {
133+
&mut self
134+
.0
135+
.bucket
136+
.get_mut(self.0.key)
137+
.expect("We can only build a ConnectedEntry if the entry is in the bucket; QED")
138+
.value
139+
}
140+
131141
/// Sets the status of the entry.
132142
/// This can fail if the new state violates buckets or table conditions.
133143
pub fn update(

0 commit comments

Comments
 (0)