From ed9a3d5de3827f41f7a3776fbf4ca173a4b381b0 Mon Sep 17 00:00:00 2001 From: Brad Dunbar Date: Sat, 3 Sep 2022 09:23:54 -0400 Subject: [PATCH 1/2] Add HashSet#raw_table Just like #335 did for `HashMap`, I'd like to add access to the underlying `RawTable` for `HashSet`. I intend to use it in conjunction with #354 to pull random elements from a `HashSet`. --- src/set.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/set.rs b/src/set.rs index c3e14affe1..547738d718 100644 --- a/src/set.rs +++ b/src/set.rs @@ -1,3 +1,5 @@ +#[cfg(feature = "raw")] +use crate::raw::RawTable; use crate::{Equivalent, TryReserveError}; use alloc::borrow::ToOwned; use core::fmt; @@ -1135,6 +1137,26 @@ where None => None, } } + + /// Returns a mutable reference to the [`RawTable`] used underneath [`HashSet`]. + /// This function is only available if the `raw` feature of the crate is enabled. + /// + /// # Note + /// + /// Calling the function safe, but using raw hash table API's may require + /// unsafe functions or blocks. + /// + /// `RawTable` API gives the lowest level of control under the set that can be useful + /// for extending the HashSet's API, but may lead to *[undefined behavior]*. + /// + /// [`HashSet`]: struct.HashSet.html + /// [`RawTable`]: raw/struct.RawTable.html + /// [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html + #[cfg(feature = "raw")] + #[cfg_attr(feature = "inline-more", inline)] + pub fn raw_table(&mut self) -> &mut RawTable<(T, ()), A> { + self.map.raw_table() + } } impl PartialEq for HashSet From 6041b5aef6ad990a379fd624b953c7ec26d62e18 Mon Sep 17 00:00:00 2001 From: Brad Dunbar Date: Thu, 8 Sep 2022 08:57:32 -0400 Subject: [PATCH 2/2] Tweak some grammar in docs. --- src/map.rs | 2 +- src/set.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/map.rs b/src/map.rs index 6a1e18c23b..9696de665d 100644 --- a/src/map.rs +++ b/src/map.rs @@ -1996,7 +1996,7 @@ impl HashMap { /// /// # Note /// - /// Calling the function safe, but using raw hash table API's may require + /// Calling this function is safe, but using the raw hash table API may require /// unsafe functions or blocks. /// /// `RawTable` API gives the lowest level of control under the map that can be useful diff --git a/src/set.rs b/src/set.rs index 547738d718..f91cb54fcb 100644 --- a/src/set.rs +++ b/src/set.rs @@ -1143,7 +1143,7 @@ where /// /// # Note /// - /// Calling the function safe, but using raw hash table API's may require + /// Calling this function is safe, but using the raw hash table API may require /// unsafe functions or blocks. /// /// `RawTable` API gives the lowest level of control under the set that can be useful