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

Implement Default for iterators #542

Merged
merged 1 commit into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
66 changes: 66 additions & 0 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2447,6 +2447,14 @@ pub struct IntoKeys<K, V, A: Allocator = Global> {
inner: IntoIter<K, V, A>,
}

impl<K, V, A: Allocator> Default for IntoKeys<K, V, A> {
#[cfg_attr(feature = "inline-more", inline)]
fn default() -> Self {
Self {
inner: Default::default(),
}
}
}
impl<K, V, A: Allocator> Iterator for IntoKeys<K, V, A> {
type Item = K;

Expand Down Expand Up @@ -2517,6 +2525,14 @@ pub struct IntoValues<K, V, A: Allocator = Global> {
inner: IntoIter<K, V, A>,
}

impl<K, V, A: Allocator> Default for IntoValues<K, V, A> {
#[cfg_attr(feature = "inline-more", inline)]
fn default() -> Self {
Self {
inner: Default::default(),
}
}
}
impl<K, V, A: Allocator> Iterator for IntoValues<K, V, A> {
type Item = V;

Expand Down Expand Up @@ -4720,6 +4736,15 @@ impl<K, V, S, A: Allocator> IntoIterator for HashMap<K, V, S, A> {
}
}

impl<'a, K, V> Default for Iter<'a, K, V> {
#[cfg_attr(feature = "inline-more", inline)]
fn default() -> Self {
Self {
inner: Default::default(),
marker: PhantomData,
}
}
}
impl<'a, K, V> Iterator for Iter<'a, K, V> {
type Item = (&'a K, &'a V);

Expand Down Expand Up @@ -4759,6 +4784,15 @@ impl<K, V> ExactSizeIterator for Iter<'_, K, V> {

impl<K, V> FusedIterator for Iter<'_, K, V> {}

impl<'a, K, V> Default for IterMut<'a, K, V> {
#[cfg_attr(feature = "inline-more", inline)]
fn default() -> Self {
Self {
inner: Default::default(),
marker: PhantomData,
}
}
}
impl<'a, K, V> Iterator for IterMut<'a, K, V> {
type Item = (&'a K, &'a mut V);

Expand Down Expand Up @@ -4807,6 +4841,14 @@ where
}
}

impl<K, V, A: Allocator> Default for IntoIter<K, V, A> {
#[cfg_attr(feature = "inline-more", inline)]
fn default() -> Self {
Self {
inner: Default::default(),
}
}
}
impl<K, V, A: Allocator> Iterator for IntoIter<K, V, A> {
type Item = (K, V);

Expand Down Expand Up @@ -4841,6 +4883,14 @@ impl<K: Debug, V: Debug, A: Allocator> fmt::Debug for IntoIter<K, V, A> {
}
}

impl<'a, K, V> Default for Keys<'a, K, V> {
#[cfg_attr(feature = "inline-more", inline)]
fn default() -> Self {
Self {
inner: Default::default(),
}
}
}
impl<'a, K, V> Iterator for Keys<'a, K, V> {
type Item = &'a K;

Expand Down Expand Up @@ -4873,6 +4923,14 @@ impl<K, V> ExactSizeIterator for Keys<'_, K, V> {
}
impl<K, V> FusedIterator for Keys<'_, K, V> {}

impl<'a, K, V> Default for Values<'a, K, V> {
#[cfg_attr(feature = "inline-more", inline)]
fn default() -> Self {
Self {
inner: Default::default(),
}
}
}
impl<'a, K, V> Iterator for Values<'a, K, V> {
type Item = &'a V;

Expand Down Expand Up @@ -4905,6 +4963,14 @@ impl<K, V> ExactSizeIterator for Values<'_, K, V> {
}
impl<K, V> FusedIterator for Values<'_, K, V> {}

impl<'a, K, V> Default for ValuesMut<'a, K, V> {
#[cfg_attr(feature = "inline-more", inline)]
fn default() -> Self {
Self {
inner: Default::default(),
}
}
}
impl<'a, K, V> Iterator for ValuesMut<'a, K, V> {
type Item = &'a mut V;

Expand Down
16 changes: 16 additions & 0 deletions src/raw/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4112,6 +4112,13 @@ impl<T> Clone for RawIter<T> {
}
}
}
impl<T> Default for RawIter<T> {
#[cfg_attr(feature = "inline-more", inline)]
fn default() -> Self {
// SAFETY: Because the table is static, it always outlives the iter.
unsafe { RawTableInner::NEW.iter() }
}
}

impl<T> Iterator for RawIter<T> {
type Item = Bucket<T>;
Expand Down Expand Up @@ -4330,6 +4337,15 @@ impl<T, A: Allocator> Drop for RawIntoIter<T, A> {
}
}

impl<T, A: Allocator> Default for RawIntoIter<T, A> {
fn default() -> Self {
Self {
iter: Default::default(),
allocation: None,
marker: PhantomData,
}
}
}
impl<T, A: Allocator> Iterator for RawIntoIter<T, A> {
type Item = T;

Expand Down
16 changes: 16 additions & 0 deletions src/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1832,6 +1832,14 @@ impl<K> Clone for Iter<'_, K> {
}
}
}
impl<K> Default for Iter<'_, K> {
#[cfg_attr(feature = "inline-more", inline)]
fn default() -> Self {
Iter {
iter: Default::default(),
}
}
}
impl<'a, K> Iterator for Iter<'a, K> {
type Item = &'a K;

Expand Down Expand Up @@ -1866,6 +1874,14 @@ impl<K: fmt::Debug> fmt::Debug for Iter<'_, K> {
}
}

impl<K, A: Allocator> Default for IntoIter<K, A> {
#[cfg_attr(feature = "inline-more", inline)]
fn default() -> Self {
IntoIter {
iter: Default::default(),
}
}
}
impl<K, A: Allocator> Iterator for IntoIter<K, A> {
type Item = K;

Expand Down
26 changes: 26 additions & 0 deletions src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1835,6 +1835,15 @@ pub struct Iter<'a, T> {
marker: PhantomData<&'a T>,
}

impl<'a, T> Default for Iter<'a, T> {
#[cfg_attr(feature = "inline-more", inline)]
fn default() -> Self {
Iter {
inner: Default::default(),
marker: PhantomData,
}
}
}
impl<'a, T> Iterator for Iter<'a, T> {
type Item = &'a T;

Expand Down Expand Up @@ -1881,6 +1890,15 @@ pub struct IterMut<'a, T> {
marker: PhantomData<&'a mut T>,
}

impl<'a, T> Default for IterMut<'a, T> {
#[cfg_attr(feature = "inline-more", inline)]
fn default() -> Self {
IterMut {
inner: Default::default(),
marker: PhantomData,
}
}
}
impl<'a, T> Iterator for IterMut<'a, T> {
type Item = &'a mut T;

Expand Down Expand Up @@ -1931,6 +1949,14 @@ where
inner: RawIntoIter<T, A>,
}

impl<T, A: Allocator> Default for IntoIter<T, A> {
#[cfg_attr(feature = "inline-more", inline)]
fn default() -> Self {
IntoIter {
inner: Default::default(),
}
}
}
impl<T, A> Iterator for IntoIter<T, A>
where
A: Allocator,
Expand Down
Loading