-impl<'a> Entry<'a> {
- /// Returns a mutable reference to the entry if occupied, or the VacantEntry if vacant.
- pub fn get(self) -> Result<&'a mut Any, VacantEntry<'a>> {
+impl<'a, A: ?Sized + UncheckedAnyExt> Entry<'a, A> {
+ /// Ensures a value is in the entry by inserting the default if empty, and returns
+ /// a mutable reference to the value in the entry.
+ ///
+ /// # Safety
+ ///
+ /// The type ID of `default` must match the entry’s key, or *undefined behaviour* occurs.
+ #[inline]
+ pub unsafe fn or_insert(self, default: Box<A>) -> &'a mut A {
+ match self {
+ Entry::Occupied(inner) => inner.into_mut(),
+ Entry::Vacant(inner) => inner.insert(default),
+ }
+ }
+
+ /// Ensures a value is in the entry by inserting the result of the default function if empty,
+ /// and returns a mutable reference to the value in the entry.
+ ///
+ /// # Safety
+ ///
+ /// The type ID of the value returned by `default` must match the entry’s key,
+ /// or *undefined behaviour* occurs.
+ #[inline]
+ pub unsafe fn or_insert_with<F: FnOnce() -> Box<A>>(self, default: F) -> &'a mut A {