Open
Description
Feature gate: #![feature(hash_set_entry)]
This is a tracking issue for Entry
and entry-like methods on HashSet
.
Public API
impl<T, S> HashSet<T, S>
where
T: Eq + Hash,
S: BuildHasher,
{
pub fn get_or_insert(&mut self, value: T) -> &T {...}
pub fn get_or_insert_with<Q: ?Sized, F>(&mut self, value: &Q, f: F) -> &T
where
T: Borrow<Q>,
Q: Hash + Eq,
F: FnOnce(&Q) -> T,
{...}
pub fn entry(&mut self, value: T) -> Entry<'_, T, S> {...}
}
pub enum Entry<'a, T, S> {
Occupied(OccupiedEntry<'a, T, S>),
Vacant(VacantEntry<'a, T, S>),
}
pub struct OccupiedEntry<'a, T, S> {...}
pub struct VacantEntry<'a, T, S> {...}
impl<T: fmt::Debug, S> fmt::Debug for Entry<'_, T, S> {...}
impl<T: fmt::Debug, S> fmt::Debug for OccupiedEntry<'_, T, S> {...}
impl<T: fmt::Debug, S> fmt::Debug for VacantEntry<'_, T, S> {...}
impl<'a, T, S> Entry<'a, T, S> {
pub fn insert(self) -> OccupiedEntry<'a, T, S>
where
T: Hash,
S: BuildHasher,
{...}
pub fn or_insert(self)
where
T: Hash,
S: BuildHasher,
{...}
pub fn get(&self) -> &T {...}
}
impl<T, S> OccupiedEntry<'_, T, S> {
pub fn get(&self) -> &T {...}
pub fn remove(self) -> T {...}
}
impl<'a, T, S> VacantEntry<'a, T, S> {
pub fn get(&self) -> &T {...}
pub fn into_value(self) -> T {...}
pub fn insert(self)
where
T: Hash,
S: BuildHasher,
{...}
}
The get_or_insert[_with]
methods provide a simplification of the Entry
API for HashSet
, with
names chosen to match the similar methods on Option
. The full Entry
API mimics that
of HashMap
, though without methods for the map value (which is just ()
in a set).
Steps / History
- Initial methods: Add entry-like methods to HashSet #60894
- Fuller
Entry
API: Add Set entry API #120077 - Final comment period (FCP)1
- Stabilization PR
Unresolved Questions
- None yet.
See also #133549 for BTreeSet
.
Footnotes
Metadata
Metadata
Assignees
Labels
Area: `std::collections`Blocker: Implemented in the nightly compiler and unstable.Category: An issue tracking the progress of sth. like the implementation of an RFCLibs issues that are tracked on the team's project board.Relevant to the library API team, which will review and decide on the PR/issue.