Merge rust-bitcoin/rust-bitcoin#3188: Add blanket impl of io traits for `&mut T`

4ead0adcb5 Add blanket impl of io traits for `&mut T` (Martin Habovstiak)

Pull request description:

  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.

  Note: this is in part an experiment to see if this is API breaking. I suspect it might be.

ACKs for top commit:
  apoelstra:
    ACK 4ead0adcb5 successfully ran local tests
  tcharding:
    ACK 4ead0adcb5

Tree-SHA512: 1e4411fdf019f3793e6366eda7e8b46246e3263bd7e41802877c20cc5e8ea451a79d89b4c59204ea9c1eb590054975de52a791a9d17a1d180a5cfac316efa959
This commit is contained in:
merge-script 2024-08-22 13:46:20 +00:00
commit 0845ac7e0e
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
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> {
@ -259,6 +283,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]