summaryrefslogtreecommitdiffstats
path: root/tokio/src/io/util/async_write_ext.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tokio/src/io/util/async_write_ext.rs')
-rw-r--r--tokio/src/io/util/async_write_ext.rs42
1 files changed, 42 insertions, 0 deletions
diff --git a/tokio/src/io/util/async_write_ext.rs b/tokio/src/io/util/async_write_ext.rs
new file mode 100644
index 00000000..9e40e259
--- /dev/null
+++ b/tokio/src/io/util/async_write_ext.rs
@@ -0,0 +1,42 @@
+use crate::io::util::flush::{flush, Flush};
+use crate::io::util::shutdown::{shutdown, Shutdown};
+use crate::io::util::write::{write, Write};
+use crate::io::util::write_all::{write_all, WriteAll};
+use crate::io::AsyncWrite;
+
+/// An extension trait which adds utility methods to `AsyncWrite` types.
+pub trait AsyncWriteExt: AsyncWrite {
+ /// Write a buffer into this writter, returning how many bytes were written.
+ fn write<'a>(&'a mut self, src: &'a [u8]) -> Write<'a, Self>
+ where
+ Self: Unpin,
+ {
+ write(self, src)
+ }
+
+ /// Attempt to write an entire buffer into this writter.
+ fn write_all<'a>(&'a mut self, src: &'a [u8]) -> WriteAll<'a, Self>
+ where
+ Self: Unpin,
+ {
+ write_all(self, src)
+ }
+
+ /// Flush the contents of this writer.
+ fn flush(&mut self) -> Flush<'_, Self>
+ where
+ Self: Unpin,
+ {
+ flush(self)
+ }
+
+ /// Shutdown this writer.
+ fn shutdown(&mut self) -> Shutdown<'_, Self>
+ where
+ Self: Unpin,
+ {
+ shutdown(self)
+ }
+}
+
+impl<W: AsyncWrite + ?Sized> AsyncWriteExt for W {}