Skip to content
Closed
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions library/std/src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2462,6 +2462,34 @@ impl<R: Read> Iterator for Bytes<R> {
};
}
}

default fn size_hint(&self) -> (usize, Option<usize>) {
Comment thread
Xavientois marked this conversation as resolved.
Outdated
(&self.inner as &dyn SizeHint).size_hint()
Comment thread
Xavientois marked this conversation as resolved.
Outdated
}
}

trait SizeHint {
fn lower_bound(&self) -> usize;

fn upper_bound(&self) -> Option<usize> {
None
}

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

impl<T> SizeHint for T {
default fn lower_bound(&self) -> usize {
0
}
}

impl<T> SizeHint for BufReader<T> {
fn lower_bound(&self) -> usize {
self.buffer().len()
}
}

/// An iterator over the contents of an instance of `BufRead` split on a
Expand Down