Skip to content

Add ExactSizeIterator, FusedIterator, and DoubleEndedIterator on IntoIter types#628

Merged
sgued merged 2 commits intorust-embedded:mainfrom
therealbnut:more_into_iter_traits
Nov 4, 2025
Merged

Add ExactSizeIterator, FusedIterator, and DoubleEndedIterator on IntoIter types#628
sgued merged 2 commits intorust-embedded:mainfrom
therealbnut:more_into_iter_traits

Conversation

@therealbnut
Copy link
Copy Markdown
Contributor

@therealbnut therealbnut commented Nov 3, 2025

Addresses #626 by implementing missing traits on the IntoIter types. Specifically:

  • Added FusedIterator to vec::IntoIter, deque::IntoIter, index_map::IntoIter and linear_map::IntoIter.
  • Added ExactSizeIterator to vec::IntoIter, deque::IntoIter, index_map::IntoIter and linear_map::IntoIter.
  • Added DoubleEndedIterator to vec::IntoIter and deque::IntoIter.

I didn't implement DoubleEndedIterator on the Map types, as their reference-based iterators didn't have it. Even if there was reference implementations, there wasn't a way to do it that would make sense without changing existing behaviour and/or the structures themselves.

Comment thread src/index_map.rs
assert_eq!(v, *src.get(k).unwrap());
assert_eq!(v, src.remove(k).unwrap());
}
assert!(src.is_empty());
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this check as previously this test would pass if the iterator only returned None.

Comment thread src/linear_map.rs
for (k, v) in clone.into_iter() {
assert_eq!(v, src.remove(k).unwrap());
}
assert!(src.is_empty());
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this check as previously this test would pass if the iterator only returned None.

@therealbnut therealbnut marked this pull request as ready for review November 3, 2025 23:51
@therealbnut therealbnut changed the title Add more IntoIter traits Add ExactSizeIterator, FusedIterator, and DoubleEndedIterator on IntoIter types Nov 4, 2025
Copy link
Copy Markdown
Contributor

@sgued sgued left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution and the updated tests.

@sgued sgued added this pull request to the merge queue Nov 4, 2025
Merged via the queue into rust-embedded:main with commit 38c004e Nov 4, 2025
21 checks passed
@therealbnut therealbnut deleted the more_into_iter_traits branch November 6, 2025 05:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants