Skip to content

Commit

Permalink
Merge pull request #62 from xacrimon/i61
Browse files Browse the repository at this point in the history
Fixed #61.
  • Loading branch information
xacrimon authored Mar 9, 2020
2 parents 749c1da + af348f4 commit eb2e397
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/mapref/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ impl<'a, K: Eq + Hash, V, S: BuildHasher> Entry<'a, K, V, S> {
Entry::Vacant(entry) => entry.insert(value()),
}
}

#[inline]
pub fn or_try_insert_with<E>(
self,
value: impl FnOnce() -> Result<V, E>,
) -> Result<RefMut<'a, K, V, S>, E> {
match self {
Entry::Occupied(entry) => Ok(entry.into_ref()),
Entry::Vacant(entry) => Ok(entry.insert(value()?)),
}
}
}

pub struct VacantEntry<'a, K, V, S> {
Expand Down

0 comments on commit eb2e397

Please sign in to comment.