Add UnordMap::try_insert

This commit is contained in:
Waffle Lapkin 2024-04-29 01:53:54 +02:00
parent fe9c5e6510
commit 3c815a644c
2 changed files with 7 additions and 0 deletions

View File

@ -25,6 +25,7 @@
#![feature(lazy_cell)]
#![feature(lint_reasons)]
#![feature(macro_metavar_expr)]
#![feature(map_try_insert)]
#![feature(maybe_uninit_uninit_array)]
#![feature(min_specialization)]
#![feature(negative_impls)]

View File

@ -4,6 +4,7 @@
use rustc_hash::{FxHashMap, FxHashSet};
use rustc_macros::{Decodable_Generic, Encodable_Generic};
use std::collections::hash_map::OccupiedError;
use std::{
borrow::{Borrow, BorrowMut},
collections::hash_map::Entry,
@ -469,6 +470,11 @@ pub fn insert(&mut self, k: K, v: V) -> Option<V> {
self.inner.insert(k, v)
}
#[inline]
pub fn try_insert(&mut self, k: K, v: V) -> Result<&mut V, OccupiedError<'_, K, V>> {
self.inner.try_insert(k, v)
}
#[inline]
pub fn contains_key<Q: ?Sized>(&self, k: &Q) -> bool
where