Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make HashSet::insert return OccupiedEntry #495

Merged
merged 1 commit into from
Feb 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions src/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@ where
/// match singles.entry(ch) {
/// Vacant(single_entry) => {
/// // We found a new character for the first time.
/// single_entry.insert()
/// single_entry.insert();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This exemplifies how it was a breaking change to return something other than ().

/// }
/// Occupied(single_entry) => {
/// // We've already seen this once, "move" it to dupes.
Expand Down Expand Up @@ -2211,7 +2211,7 @@ impl<T: fmt::Debug, S, A: Allocator> fmt::Debug for OccupiedEntry<'_, T, S, A> {
///
/// // Nonexistent key (insert)
/// match set.entry("b") {
/// Entry::Vacant(view) => view.insert(),
/// Entry::Vacant(view) => { view.insert(); },
/// Entry::Occupied(_) => unreachable!(),
/// }
/// assert!(set.contains("b") && set.len() == 2);
Expand Down Expand Up @@ -2247,7 +2247,7 @@ impl<'a, T, S, A: Allocator> Entry<'a, T, S, A> {
{
match self {
Entry::Occupied(entry) => entry,
Entry::Vacant(entry) => entry.insert_entry(),
Entry::Vacant(entry) => entry.insert(),
}
}

Expand Down Expand Up @@ -2442,16 +2442,7 @@ impl<'a, T, S, A: Allocator> VacantEntry<'a, T, S, A> {
/// assert!(set.contains("poneyland"));
/// ```
#[cfg_attr(feature = "inline-more", inline)]
pub fn insert(self)
where
T: Hash,
S: BuildHasher,
{
self.inner.insert(());
}

#[cfg_attr(feature = "inline-more", inline)]
fn insert_entry(self) -> OccupiedEntry<'a, T, S, A>
pub fn insert(self) -> OccupiedEntry<'a, T, S, A>
where
T: Hash,
S: BuildHasher,
Expand Down
Loading