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

Added implementations for IntoIter and IterMut #16

Merged
merged 5 commits into from
Oct 10, 2021
Merged
Changes from 1 commit
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
28 changes: 27 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
use num_traits::{One, Zero};

use std::borrow::Borrow;
use std::collections::{hash_map::Iter, HashMap};
use std::collections::{hash_map::{Iter, IntoIter, IterMut}, HashMap};
use std::hash::Hash;
use std::iter;
use std::ops::{Add, AddAssign, BitAnd, BitOr, Deref, DerefMut, Index, IndexMut, Sub, SubAssign};
Expand Down Expand Up @@ -553,6 +553,32 @@ where
}
}

impl<T, N> IntoIterator for Counter<T, N>
where
T: Hash + Eq,
N: PartialOrd + AddAssign + SubAssign + Zero + One,
TinBryn marked this conversation as resolved.
Show resolved Hide resolved
{
type Item = (T, N);
type IntoIter = IntoIter<T, N>;
TinBryn marked this conversation as resolved.
Show resolved Hide resolved

fn into_iter(self) -> Self::IntoIter {
self.map.into_iter()
}
}

impl<'a, T, N> IntoIterator for &'a mut Counter<T, N>
where
T: Hash + Eq,
N: PartialOrd + AddAssign + SubAssign + Zero + One,
{
type Item = (&'a T, &'a mut N);
type IntoIter = IterMut<'a, T, N>;

fn into_iter(self) -> Self::IntoIter {
self.map.iter_mut()
}
}

impl<T, Q, N> Index<&'_ Q> for Counter<T, N>
where
T: Hash + Eq + Borrow<Q>,
Expand Down