Skip to content

Commit

Permalink
add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
StoicDeveloper committed Jun 11, 2023
1 parent 85da253 commit 373f965
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
14 changes: 8 additions & 6 deletions futures-util/src/stream/mapped_futures/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ pub struct IntoIter<K: Hash + Eq, Fut: Unpin> {
pub(super) inner: MappedFutures<K, Fut>,
}

/// Immutable iterator over all keys in the mapping.
pub struct Keys<'a, K: Hash + Eq, Fut> {
pub(super) inner: std::iter::Map<
std::collections::hash_set::Iter<'a, HashTask<K, Fut>>,
Box<dyn FnMut(&'a HashTask<K, Fut>) -> &'a K>,
>,
}

impl<K: Hash + Eq, Fut: Unpin> Iterator for IntoIter<K, Fut> {
type Item = Fut;

Expand Down Expand Up @@ -161,12 +169,6 @@ impl<'a, K: Hash + Eq, Fut: Unpin> Iterator for Iter<'a, K, Fut> {

impl<K: Hash + Eq, Fut: Unpin> ExactSizeIterator for Iter<'_, K, Fut> {}

pub struct Keys<'a, K: Hash + Eq, Fut> {
pub(super) inner: std::iter::Map<
std::collections::hash_set::Iter<'a, HashTask<K, Fut>>,
Box<dyn FnMut(&'a HashTask<K, Fut>) -> &'a K>,
>,
}
impl<K: Hash + Eq, Fut: Unpin> ExactSizeIterator for Keys<'_, K, Fut> {}

impl<'a, K: Hash + Eq, Fut> Iterator for Keys<'a, K, Fut> {
Expand Down
1 change: 1 addition & 0 deletions futures-util/src/stream/mapped_futures/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ impl<K: Hash + Eq, Fut> MappedFutures<K, Fut> {
None
}

/// Returns an iterator of keys in the mapping.
pub fn keys<'a>(&'a self) -> Keys<'a, K, Fut> {
Keys {
inner: self.hash_set.iter().map(Box::new(|hash_task| HashTask::key_unwrap(hash_task))),
Expand Down

0 comments on commit 373f965

Please sign in to comment.