From 4ead0adcb54522302facbc486aef548e6f5790fa Mon Sep 17 00:00:00 2001 From: Martin Habovstiak Date: Mon, 19 Aug 2024 18:06:23 +0200 Subject: [PATCH] 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. --- io/src/lib.rs | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/io/src/lib.rs b/io/src/lib.rs index 1fc5dd53e..17d345c31 100644 --- a/io/src/lib.rs +++ b/io/src/lib.rs @@ -153,6 +153,30 @@ impl<'a, R: BufRead + ?Sized> BufRead for Take<'a, R> { } } +impl Read for &'_ mut T { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> Result { + (**self).read(buf) + } + + #[inline] + fn read_exact(&mut self, buf: &mut [u8]) -> Result<()> { + (**self).read_exact(buf) + } +} + +impl 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 { @@ -261,6 +285,23 @@ pub trait Write { } } +impl Write for &'_ mut T { + #[inline] + fn write(&mut self, buf: &[u8]) -> Result { + (**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 { #[inline]