Skip to content

Commit 80d6054

Browse files
committed
use exactsizeiterator for batchdrain
1 parent 2491162 commit 80d6054

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

spillway/src/receiver.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl<T> Receiver<T> {
109109
/// * None when all senders have been dropped and the Receiver is caught up. The Receiver will never receive more messages and you should drop it.
110110
/// * You will never receive an empty iterator.
111111
#[inline]
112-
pub async fn next_batch<'a>(&'a mut self) -> Option<impl Iterator<Item = T> + 'a> {
112+
pub async fn next_batch<'a>(&'a mut self) -> Option<impl ExactSizeIterator<Item = T> + 'a> {
113113
std::future::poll_fn(|context| {
114114
match self.poll_next(context) {
115115
std::task::Poll::Ready(Some(next)) => {
@@ -140,6 +140,17 @@ impl<T> Iterator for BatchDrain<'_, T> {
140140
fn next(&mut self) -> Option<Self::Item> {
141141
self.buffer.pop_front()
142142
}
143+
144+
fn size_hint(&self) -> (usize, Option<usize>) {
145+
let len = self.buffer.len();
146+
(len, Some(len))
147+
}
148+
}
149+
150+
impl<T> ExactSizeIterator for BatchDrain<'_, T> {
151+
fn len(&self) -> usize {
152+
self.buffer.len()
153+
}
143154
}
144155

145156
#[cfg(test)]

0 commit comments

Comments
 (0)