diff --git a/benches/batch.rs b/benches/batch.rs index 0066125..e0bfad1 100644 --- a/benches/batch.rs +++ b/benches/batch.rs @@ -15,8 +15,8 @@ async fn sleep() { #[divan::bench_group] mod futures_unordered { - use futures_buffered::FuturesUnorderedBounded; use futures::{stream::FuturesUnordered, StreamExt}; + use futures_buffered::FuturesUnorderedBounded; use crate::sleep; @@ -71,8 +71,8 @@ mod futures_unordered { #[divan::bench_group] mod buffer_unordered { - use futures_buffered::BufferedStreamExt; use futures::{stream, StreamExt}; + use futures_buffered::BufferedStreamExt; use crate::sleep; @@ -107,8 +107,8 @@ mod buffer_unordered { #[divan::bench_group] mod buffer_ordered { - use futures_buffered::BufferedStreamExt; use futures::{stream, StreamExt}; + use futures_buffered::BufferedStreamExt; use crate::sleep; diff --git a/src/buffered/ordered.rs b/src/buffered/ordered.rs index ba41302..e1987aa 100644 --- a/src/buffered/ordered.rs +++ b/src/buffered/ordered.rs @@ -63,19 +63,18 @@ where } fn size_hint(&self) -> (usize, Option) { - match &self.stream { - Some(s) => { - let queue_len = self.in_progress_queue.len(); - let (lower, upper) = s.size_hint(); - let lower = lower.saturating_add(queue_len); - let upper = match upper { - Some(x) => x.checked_add(queue_len), - None => None, - }; - (lower, upper) - } - _ => (0, Some(0)), - } + let queue_len = self.in_progress_queue.len(); + let (lower, upper) = self + .stream + .as_ref() + .map(|s| s.size_hint()) + .unwrap_or((0, Some(0))); + let lower = lower.saturating_add(queue_len); + let upper = match upper { + Some(x) => x.checked_add(queue_len), + None => None, + }; + (lower, upper) } } diff --git a/src/buffered/unordered.rs b/src/buffered/unordered.rs index ac13b6d..57fc7f4 100644 --- a/src/buffered/unordered.rs +++ b/src/buffered/unordered.rs @@ -116,19 +116,18 @@ where } fn size_hint(&self) -> (usize, Option) { - match &self.stream { - Some(s) => { - let queue_len = self.in_progress_queue.len(); - let (lower, upper) = s.size_hint(); - let lower = lower.saturating_add(queue_len); - let upper = match upper { - Some(x) => x.checked_add(queue_len), - None => None, - }; - (lower, upper) - } - _ => (0, Some(0)), - } + let queue_len = self.in_progress_queue.len(); + let (lower, upper) = self + .stream + .as_ref() + .map(|s| s.size_hint()) + .unwrap_or((0, Some(0))); + let lower = lower.saturating_add(queue_len); + let upper = match upper { + Some(x) => x.checked_add(queue_len), + None => None, + }; + (lower, upper) } }