summaryrefslogtreecommitdiffstats
path: root/tokio/tests/io_write.rs
diff options
context:
space:
mode:
authorCarl Lerche <me@carllerche.com>2019-10-26 08:02:49 -0700
committerGitHub <noreply@github.com>2019-10-26 08:02:49 -0700
commit987ba7373cf95c570bf23768c6021f7a7508286e (patch)
tree616c62a65cb6b0c7e4c3e31f92f01c8d4749b0c3 /tokio/tests/io_write.rs
parent227533d456fe32e48ffcd3796f1e6c8f9318b230 (diff)
io: move into `tokio` crate (#1691)
A step towards collapsing Tokio sub crates into a single `tokio` crate (#1318). The `io` implementation is now provided by the main `tokio` crate. Functionality can be opted out of by using the various net related feature flags.
Diffstat (limited to 'tokio/tests/io_write.rs')
-rw-r--r--tokio/tests/io_write.rs46
1 files changed, 46 insertions, 0 deletions
diff --git a/tokio/tests/io_write.rs b/tokio/tests/io_write.rs
new file mode 100644
index 00000000..733b38c9
--- /dev/null
+++ b/tokio/tests/io_write.rs
@@ -0,0 +1,46 @@
+#![warn(rust_2018_idioms)]
+
+use tokio::io::{AsyncWrite, AsyncWriteExt};
+use tokio_test::assert_ok;
+
+use bytes::BytesMut;
+use std::io;
+use std::pin::Pin;
+use std::task::{Context, Poll};
+
+#[tokio::test]
+async fn write() {
+ struct Wr {
+ buf: BytesMut,
+ cnt: usize,
+ }
+
+ impl AsyncWrite for Wr {
+ fn poll_write(
+ mut self: Pin<&mut Self>,
+ _cx: &mut Context<'_>,
+ buf: &[u8],
+ ) -> Poll<io::Result<usize>> {
+ assert_eq!(self.cnt, 0);
+ self.buf.extend(&buf[0..4]);
+ Ok(4).into()
+ }
+
+ fn poll_flush(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<()>> {
+ Ok(()).into()
+ }
+
+ fn poll_shutdown(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<()>> {
+ Ok(()).into()
+ }
+ }
+
+ let mut wr = Wr {
+ buf: BytesMut::with_capacity(64),
+ cnt: 0,
+ };
+
+ let n = assert_ok!(wr.write(b"hello world").await);
+ assert_eq!(n, 4);
+ assert_eq!(wr.buf, b"hell"[..]);
+}