Skip to content

Commit

Permalink
Make new method public and improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
JelteF committed Aug 23, 2023
1 parent 64d00fa commit f48dbcf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/btreemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl<K: Eq + Ord, V: Default> DefaultBTreeMap<K, V> {
/// as the default for missing keys.
/// This is desired default for most use cases, if your case requires a
/// different default you should use the `with_default()` constructor.
fn new() -> DefaultBTreeMap<K, V> {
pub fn new() -> DefaultBTreeMap<K, V> {
DefaultBTreeMap {
map: BTreeMap::default(),
default_fn: Box::new(|| V::default()),
Expand Down Expand Up @@ -115,6 +115,10 @@ impl<K: Eq + Ord, V> DefaultBTreeMap<K, V> {
}

/// Returns the an owned version of the default value
/// ```
/// use defaultmap::DefaultBTreeMap;
/// assert_eq!(DefaultBTreeMap::<String, i32>::new().get_default(), 0);
/// ```
pub fn get_default(&self) -> V {
self.default_fn.call()
}
Expand Down
6 changes: 5 additions & 1 deletion src/hashmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl<K: Eq + Hash, V: Default> DefaultHashMap<K, V> {
/// as the default for missing keys.
/// This is desired default for most use cases, if your case requires a
/// different default you should use the `with_default()` constructor.
fn new() -> DefaultHashMap<K, V> {
pub fn new() -> DefaultHashMap<K, V> {
DefaultHashMap {
map: HashMap::default(),
default_fn: Box::new(|| V::default()),
Expand Down Expand Up @@ -116,6 +116,10 @@ impl<K: Eq + Hash, V> DefaultHashMap<K, V> {
}

/// Returns the an owned version of the default value
/// ```
/// use defaultmap::DefaultHashMap;
/// assert_eq!(DefaultHashMap::<String, i32>::new().get_default(), 0);
/// ```
pub fn get_default(&self) -> V {
self.default_fn.call()
}
Expand Down

0 comments on commit f48dbcf

Please sign in to comment.