Skip to content
Closed
Changes from 7 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
43 changes: 40 additions & 3 deletions library/std/src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2213,7 +2213,11 @@ impl<T: Read, U: Read> Read for Chain<T, U> {

unsafe fn initializer(&self) -> Initializer {
let initializer = self.first.initializer();
if initializer.should_initialize() { initializer } else { self.second.initializer() }
if initializer.should_initialize() {
initializer
} else {
self.second.initializer()
}
}
}

Expand All @@ -2232,7 +2236,11 @@ impl<T: BufRead, U: BufRead> BufRead for Chain<T, U> {
}

fn consume(&mut self, amt: usize) {
if !self.done_first { self.first.consume(amt) } else { self.second.consume(amt) }
if !self.done_first {
self.first.consume(amt)
} else {
self.second.consume(amt)
}
}
}

Expand Down Expand Up @@ -2448,7 +2456,7 @@ pub struct Bytes<R> {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<R: Read> Iterator for Bytes<R> {
impl<R: Read + SizeHint> Iterator for Bytes<R> {
type Item = Result<u8>;

fn next(&mut self) -> Option<Result<u8>> {
Expand All @@ -2462,6 +2470,35 @@ impl<R: Read> Iterator for Bytes<R> {
};
}
}

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

#[stable(feature = "bufreader_size_hint", since = "1.51.0")]
trait SizeHint {
fn upper_bound(&self) -> Option<usize> {
None
}

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

#[stable(feature = "bufreader_size_hint", since = "1.51.0")]
impl<T> SizeHint for T {
default fn lower_bound(&self) -> usize {
0
}
}

#[stable(feature = "bufreader_size_hint", since = "1.51.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