Tracking issue for HashSet entry APIs · Issue #60896 · rust-lang/rust (original) (raw)

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: 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

Unresolved Questions

See also #133549 for BTreeSet.

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html