Skip to content

Commit

Permalink
Add Entry::insert method
Browse files Browse the repository at this point in the history
  • Loading branch information
Avi-D-coder committed Apr 11, 2024
1 parent 161159e commit 3f65cb3
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,19 @@ impl<'a, V> Entry<'a, V> {
}
}

/// Prefer `Transaction::insert` over `Entry::insert` if you are not using any other `Entry` methods.
#[inline]
pub fn insert(self, value: V) -> &'a mut V {
match self {
Entry::Occupied(mut o) => {
o.insert(value);
o.into_mut()
}
Entry::VacantEmptyTrie(entry) => entry.insert(value),
Entry::Vacant(entry) => entry.insert(value),
}
}

#[inline]
pub fn or_insert(self, value: V) -> &'a mut V {
self.or_insert_with(|| value)
Expand Down

0 comments on commit 3f65cb3

Please sign in to comment.