Skip to content

Commit

Permalink
add custom type alias Elements<'a, T>
Browse files Browse the repository at this point in the history
the `.elements()` method was leaking the `hash_map::Keys` type. In order
to hedge against switching to hash_brown or another underlying impl in
the future, this provides a Type aliasing the current implementation so
that users won't have to put up my fickle whimsy
  • Loading branch information
lonnen committed Nov 13, 2020
1 parent 8281e7f commit 4dbf0cd
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use std::borrow::Borrow;
use std::cmp::min;
use std::collections::hash_map::{self, Entry, Keys, RandomState};
use std::collections::hash_map::{self, Entry, RandomState};
use std::collections::HashMap;
use std::fmt;
use std::hash::{BuildHasher, Hash};
Expand Down Expand Up @@ -230,7 +230,7 @@ impl<T, S> MultiSet<T, S> {
/// println!("{}", e);
/// }
/// ```
pub fn elements(&self) -> Keys<T, usize> {
pub fn elements(&self) -> Elements<T> {
self.elem_counts.keys()
}

Expand Down Expand Up @@ -1192,6 +1192,15 @@ impl<T> ExactSizeIterator for ElementCounts<'_, T> {

impl<T> FusedIterator for ElementCounts<'_, T> {}

/// An iterator over the elements of a `MultiSet`.
///
/// This `struct` is created by the [`elements`] method on [`MultiSet`].
/// See its documentation for more.
///
/// [`MultiSet`]: struct.MultiSet.html
/// [`elements`]: struct.MultiSet.html#method.elements
pub type Elements<'a, T> = std::collections::hash_map::Keys<'a, T, usize>;

/// An iterator over the items of a `MultiSet`.
///
/// This `struct` is created by the [`iter`] method on [`MultiSet`].
Expand Down

0 comments on commit 4dbf0cd

Please sign in to comment.