Implement SizeHint trait for BufReader, Emtpy, and Chain
This commit is contained in:
parent
c8e0f8aaa3
commit
96255f82c9
3 changed files with 29 additions and 8 deletions
|
@ -2239,6 +2239,20 @@ impl<T: BufRead, U: BufRead> BufRead for Chain<T, U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T, U> SizeHint for Chain<T, U> {
|
||||
fn lower_bound(&self) -> usize {
|
||||
SizeHint::lower_bound(&self.first) + SizeHint::lower_bound(&self.second)
|
||||
}
|
||||
|
||||
fn upper_bound(&self) -> Option<usize > {
|
||||
match (SizeHint::upper_bound(&self.first), SizeHint::upper_bound(&self.second)) {
|
||||
(Some(first), Some(second)) => Some(first + second),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Reader adaptor which limits the bytes read from an underlying reader.
|
||||
///
|
||||
/// This struct is generally created by calling [`take`] on a reader.
|
||||
|
@ -2491,12 +2505,6 @@ impl<T> SizeHint for T {
|
|||
}
|
||||
}
|
||||
|
||||
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
|
||||
/// particular byte.
|
||||
///
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue