From 4dbf0cd2fd6561044a2b7e2df36ed4433bff49fd Mon Sep 17 00:00:00 2001 From: lonnen Date: Fri, 13 Nov 2020 10:29:45 -0800 Subject: [PATCH] add custom type alias `Elements<'a, T>` 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 --- src/lib.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 7f1e936..ca66aad 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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}; @@ -230,7 +230,7 @@ impl MultiSet { /// println!("{}", e); /// } /// ``` - pub fn elements(&self) -> Keys { + pub fn elements(&self) -> Elements { self.elem_counts.keys() } @@ -1192,6 +1192,15 @@ impl ExactSizeIterator for ElementCounts<'_, T> { impl 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`].