Skip to content

Commit

Permalink
Implement get_default
Browse files Browse the repository at this point in the history
Fixes #13
  • Loading branch information
JelteF committed Aug 17, 2023
1 parent 2cd1790 commit eb84c41
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/btreemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ impl<K: Eq + Ord, V> DefaultBTreeMap<K, V> {
{
self.map.get(key.borrow()).unwrap_or(&self.default)
}

/// Returns the an owned version of the default value
pub fn get_default(&self) -> V {
self.default_fn.call()
}
}

impl<K: Eq + Ord, V> DefaultBTreeMap<K, V> {
Expand Down
5 changes: 5 additions & 0 deletions src/hashmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ impl<K: Eq + Hash, V> DefaultHashMap<K, V> {
{
self.map.get(key.borrow()).unwrap_or(&self.default)
}

/// Returns the an owned version of the default value
pub fn get_default(&self) -> V {
self.default_fn.call()
}
}

impl<K: Eq + Hash, V> DefaultHashMap<K, V> {
Expand Down

0 comments on commit eb84c41

Please sign in to comment.