Skip to content

Commit

Permalink
Override read_exact and write_all
Browse files Browse the repository at this point in the history
Some types override these methods to provide optimizations. Using
default implementations would bypass those overrides and lead to worse
performance.

Overriding the methods to delegate implementations directly solves the
problem.
  • Loading branch information
Kixunil committed Jul 24, 2022
1 parent 39cec17 commit 5dbcc98
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,10 @@ where
for_both!(*self, ref mut inner => inner.read(buf))
}

fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> {
for_both!(*self, ref mut inner => inner.read_exact(buf))
}

fn read_to_end(&mut self, buf: &mut std::vec::Vec<u8>) -> io::Result<usize> {
for_both!(*self, ref mut inner => inner.read_to_end(buf))
}
Expand Down Expand Up @@ -1099,6 +1103,10 @@ where
for_both!(*self, ref mut inner => inner.write(buf))
}

fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
for_both!(*self, ref mut inner => inner.write_all(buf))
}

fn flush(&mut self) -> io::Result<()> {
for_both!(*self, ref mut inner => inner.flush())
}
Expand Down

0 comments on commit 5dbcc98

Please sign in to comment.