Conceptually, I'd like to have an "extended" HashMap class that I'll call a FrequencyTable
#[derive(Clone)]
pub struct FrequencyTable<K,V>(HashMap<K,HashSet<V>>);
I'd like to define a "default" that goes over the HashMap
member.
My first attempt was
impl<K,V> std::iter::IntoIterator for FrequencyTable<K,V> {
type Item = (K,HashSet<V>);
type IntoIter = std::collections::hash_map::Iter<'static, K, HashSet<V>>;
fn into_iter(self) -> std::collections::hash_map::Iter<'static, K, HashSet<V>> {
self.0.iter()
}
}
which complains because K
and V
need lifetime bounds so I tried
impl<K,V> std::iter::IntoIterator for FrequencyTable<K,V> where K: 'static, V:'static {
type Item = (K,HashSet<V>);
type IntoIter = std::collections::hash_map::Iter<'static, K, HashSet<V>>;
fn into_iter(self) -> std::collections::hash_map::Iter<'static, K, HashSet<V>> {
self.0.iter()
}
}
which then says expected parameter 'k', found '&K' ...
But adding &
s to the variables didn't solve the error.