Skip to content

Commit

Permalink
impl size_hint for ConcurrentStream
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshuawuyts committed Mar 17, 2024
1 parent e1fab54 commit fd72179
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/concurrent_stream/enumerate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ impl<CS: ConcurrentStream> ConcurrentStream for Enumerate<CS> {
fn concurrency_limit(&self) -> Option<std::num::NonZeroUsize> {
self.inner.concurrency_limit()
}

fn size_hint(&self) -> (usize, Option<usize>) {
self.inner.size_hint()
}
}

struct EnumerateConsumer<C> {
Expand Down
4 changes: 4 additions & 0 deletions src/concurrent_stream/into_concurrent_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ where
fn concurrency_limit(&self) -> Option<std::num::NonZeroUsize> {
None
}

fn size_hint(&self) -> (usize, Option<usize>) {
self.iter.size_hint()
}
}

enum State<T> {
Expand Down
4 changes: 4 additions & 0 deletions src/concurrent_stream/limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ impl<CS: ConcurrentStream> ConcurrentStream for Limit<CS> {
fn concurrency_limit(&self) -> Option<std::num::NonZeroUsize> {
self.limit
}

fn size_hint(&self) -> (usize, Option<usize>) {
self.inner.size_hint()
}
}

struct LimitConsumer<C> {
Expand Down
4 changes: 4 additions & 0 deletions src/concurrent_stream/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ where
fn concurrency_limit(&self) -> Option<std::num::NonZeroUsize> {
self.inner.concurrency_limit()
}

fn size_hint(&self) -> (usize, Option<usize>) {
self.inner.size_hint()
}
}

// OK: validated! - all bounds should check out
Expand Down
5 changes: 5 additions & 0 deletions src/concurrent_stream/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ pub trait ConcurrentStream {
/// How much concurrency should we apply?
fn concurrency_limit(&self) -> Option<NonZeroUsize>;

/// How many items could we potentially end up returning?
fn size_hint(&self) -> (usize, Option<usize>) {
(0, None)
}

/// Creates a stream which gives the current iteration count as well as
/// the next value.
///
Expand Down
4 changes: 4 additions & 0 deletions src/concurrent_stream/passthrough.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ impl<CS: ConcurrentStream> ConcurrentStream for Passthrough<CS> {
fn concurrency_limit(&self) -> Option<std::num::NonZeroUsize> {
self.inner.concurrency_limit()
}

fn size_hint(&self) -> (usize, Option<usize>) {
self.inner.size_hint()
}
}

struct PassthroughConsumer<C> {
Expand Down

0 comments on commit fd72179

Please sign in to comment.