Thanks to the existence of the hashbrown crate, it is possible to provide no_std support for HashMap—provided that alloc is enabled.
The code itself remains unchanged; only the import statements need to be modified.
use core::hash::Hash;
use hashbrown::HashMap;
pub trait Counts: Iterator {
fn counts(self) -> HashMap<Self::Item, usize>
where
Self: Sized,
Self::Item: Eq + Hash,
{
let mut counts = HashMap::new();
self.for_each(|item| *counts.entry(item).or_default() += 1);
counts
}
}
impl<I: Iterator> Counts for I {}
Would you consider adding this support? Doing so would broaden the applicability of the APIs related to HashMap and HashSet.
Thanks to the existence of the
hashbrowncrate, it is possible to provideno_stdsupport forHashMap—provided thatallocis enabled.The code itself remains unchanged; only the import statements need to be modified.
Would you consider adding this support? Doing so would broaden the applicability of the APIs related to
HashMapandHashSet.