summaryrefslogtreecommitdiffstats
path: root/tokio/src/io/async_write.rs
diff options
context:
space:
mode:
authorSebastian Dröge <sebastian@centricular.com>2019-11-03 14:21:01 +0200
committerTaiki Endo <te316e89@gmail.com>2019-11-03 21:21:01 +0900
commit6b35a1e8b0d53524af8d07f99cf85ae81a73ef18 (patch)
tree0e3e7b232f8def9d992098ebffa9cf762e9be76d /tokio/src/io/async_write.rs
parente19bd77ef0149b3141981b36f3ebc442fae4a0b4 (diff)
impl AsyncWrite for std::io::Cursor (#1730)
Based on the implementation from the futures crate.
Diffstat (limited to 'tokio/src/io/async_write.rs')
-rw-r--r--tokio/src/io/async_write.rs72
1 files changed, 72 insertions, 0 deletions
diff --git a/tokio/src/io/async_write.rs b/tokio/src/io/async_write.rs
index dc8b852f..0489fb7c 100644
--- a/tokio/src/io/async_write.rs
+++ b/tokio/src/io/async_write.rs
@@ -209,3 +209,75 @@ impl AsyncWrite for Vec<u8> {
Poll::Ready(Ok(()))
}
}
+
+impl AsyncWrite for io::Cursor<&mut [u8]> {
+ fn poll_write(
+ mut self: Pin<&mut Self>,
+ _: &mut Context<'_>,
+ buf: &[u8],
+ ) -> Poll<io::Result<usize>> {
+ Poll::Ready(io::Write::write(&mut *self, buf))
+ }
+
+ fn poll_flush(mut self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<io::Result<()>> {
+ Poll::Ready(io::Write::flush(&mut *self))
+ }
+
+ fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
+ self.poll_flush(cx)
+ }
+}
+
+impl AsyncWrite for io::Cursor<&mut Vec<u8>> {
+ fn poll_write(
+ mut self: Pin<&mut Self>,
+ _: &mut Context<'_>,
+ buf: &[u8],
+ ) -> Poll<io::Result<usize>> {
+ Poll::Ready(io::Write::write(&mut *self, buf))
+ }
+
+ fn poll_flush(mut self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<io::Result<()>> {
+ Poll::Ready(io::Write::flush(&mut *self))
+ }
+
+ fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
+ self.poll_flush(cx)
+ }
+}
+
+impl AsyncWrite for io::Cursor<Vec<u8>> {
+ fn poll_write(
+ mut self: Pin<&mut Self>,
+ _: &mut Context<'_>,
+ buf: &[u8],
+ ) -> Poll<io::Result<usize>> {
+ Poll::Ready(io::Write::write(&mut *self, buf))
+ }
+
+ fn poll_flush(mut self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<io::Result<()>> {
+ Poll::Ready(io::Write::flush(&mut *self))
+ }
+
+ fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
+ self.poll_flush(cx)
+ }
+}
+
+impl AsyncWrite for io::Cursor<Box<[u8]>> {
+ fn poll_write(
+ mut self: Pin<&mut Self>,
+ _: &mut Context<'_>,
+ buf: &[u8],
+ ) -> Poll<io::Result<usize>> {
+ Poll::Ready(io::Write::write(&mut *self, buf))
+ }
+
+ fn poll_flush(mut self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<io::Result<()>> {
+ Poll::Ready(io::Write::flush(&mut *self))
+ }
+
+ fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
+ self.poll_flush(cx)
+ }
+}