Add blanket impl of io traits for `&mut T`

The impl wasn't previously available because we thought we can do a
blanket impl for `std` traits. We've removed the `std` blanket impl when
we realized it's broken but forgot to add the `&mut T` impls. This adds
them.
This commit is contained in:
Martin Habovstiak 2024-08-19 18:06:23 +02:00
parent c00faa0458
commit 4ead0adcb5
1 changed files with 41 additions and 0 deletions

View File

@ -153,6 +153,30 @@ impl<'a, R: BufRead + ?Sized> BufRead for Take<'a, R> {
}
}
impl<T: Read> Read for &'_ mut T {
#[inline]
fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
(**self).read(buf)
}
#[inline]
fn read_exact(&mut self, buf: &mut [u8]) -> Result<()> {
(**self).read_exact(buf)
}
}
impl<T: BufRead> BufRead for &'_ mut T {
#[inline]
fn fill_buf(&mut self) -> Result<&[u8]> {
(**self).fill_buf()
}
#[inline]
fn consume(&mut self, amount: usize) {
(**self).consume(amount)
}
}
impl Read for &[u8] {
#[inline]
fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
@ -261,6 +285,23 @@ pub trait Write {
}
}
impl<T: Write> Write for &'_ mut T {
#[inline]
fn write(&mut self, buf: &[u8]) -> Result<usize> {
(**self).write(buf)
}
#[inline]
fn write_all(&mut self, buf: &[u8]) -> Result<()> {
(**self).write_all(buf)
}
#[inline]
fn flush(&mut self) -> Result<()> {
(**self).flush()
}
}
#[cfg(feature = "alloc")]
impl Write for alloc::vec::Vec<u8> {
#[inline]