diff --git a/futures-util/src/stream/mapped_futures/iter.rs b/futures-util/src/stream/mapped_futures/iter.rs index ed7d3758e..0ec0ff489 100644 --- a/futures-util/src/stream/mapped_futures/iter.rs +++ b/futures-util/src/stream/mapped_futures/iter.rs @@ -38,6 +38,14 @@ pub struct IntoIter { pub(super) inner: MappedFutures, } +/// 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>, + Box) -> &'a K>, + >, +} + impl Iterator for IntoIter { type Item = Fut; @@ -161,12 +169,6 @@ impl<'a, K: Hash + Eq, Fut: Unpin> Iterator for Iter<'a, K, Fut> { impl 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>, - Box) -> &'a K>, - >, -} impl ExactSizeIterator for Keys<'_, K, Fut> {} impl<'a, K: Hash + Eq, Fut> Iterator for Keys<'a, K, Fut> { diff --git a/futures-util/src/stream/mapped_futures/mod.rs b/futures-util/src/stream/mapped_futures/mod.rs index bd7cc4ba3..f70d98ad0 100644 --- a/futures-util/src/stream/mapped_futures/mod.rs +++ b/futures-util/src/stream/mapped_futures/mod.rs @@ -309,6 +309,7 @@ impl MappedFutures { 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))),