From 380c042d83a349114b49c4b3210afeb8cc338c5e Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Sat, 11 Sep 2021 13:19:38 -0400 Subject: [PATCH] Pass through stream_position in ProgreessBarIter This avoids sending a stream_position update and also preserves optimizations that the underlying object may have made for stream_position. For example, when wrapping a `BufReader` object, adding this impl allows the use of `.stream_position()` in functions that take a generic `Seek` object without causing the performance drop associated with the default impl of `stream_position` calling `seek(SeekFrom::Current(0))` and throwing away the buffer each time. --- src/iter.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/iter.rs b/src/iter.rs index cc038779..31b5c8a7 100644 --- a/src/iter.rs +++ b/src/iter.rs @@ -134,6 +134,11 @@ impl io::Seek for ProgressBarIter { pos }) } + // Pass this through to preserve optimizations that the inner I/O object may use here + // Also avoid sending a set_position update when the position hasn't changed + fn stream_position(&mut self) -> io::Result { + self.it.stream_position() + } } impl io::Write for ProgressBarIter {