Skip to content

Commit 639f131

Browse files
authored
Merge pull request #47 from sunfishcode/sunfishcode/readwrite-impls
Implement `AsyncRead`/`AsyncWrite` for `&mut T`.
2 parents d8ce53c + 26e2142 commit 639f131

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/io/read.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,15 @@ pub trait AsyncRead {
2525
}
2626
}
2727
}
28+
29+
impl<R: AsyncRead + ?Sized> AsyncRead for &mut R {
30+
#[inline]
31+
async fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
32+
(*self).read(buf).await
33+
}
34+
35+
#[inline]
36+
async fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
37+
(*self).read_to_end(buf).await
38+
}
39+
}

src/io/write.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,20 @@ pub trait AsyncWrite {
1717
}
1818
}
1919
}
20+
21+
impl<W: AsyncWrite + ?Sized> AsyncWrite for &mut W {
22+
#[inline]
23+
async fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
24+
(*self).write(buf).await
25+
}
26+
27+
#[inline]
28+
async fn flush(&mut self) -> io::Result<()> {
29+
(*self).flush().await
30+
}
31+
32+
#[inline]
33+
async fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
34+
(*self).write_all(buf).await
35+
}
36+
}

0 commit comments

Comments
 (0)