about summary refs log tree commit diff
path: root/src/libstd/sys/wasi/stdio.rs
diff options
context:
space:
mode:
authorSteven Fackler <sfackler@gmail.com>2020-01-03 11:26:05 -0800
committerSteven Fackler <sfackler@gmail.com>2020-04-26 04:23:39 -0700
commit15262ec6be6fcfc9f27e174a0714d5a62e775fb0 (patch)
treea962ae80ff3cbdb331c76426c200cdec0d82219c /src/libstd/sys/wasi/stdio.rs
parent019ab732ce63a117cbb446db1488916c5c0bd2a7 (diff)
downloadrust-15262ec6be6fcfc9f27e174a0714d5a62e775fb0.tar.gz
rust-15262ec6be6fcfc9f27e174a0714d5a62e775fb0.zip
Add Read/Write::can_read/write_vectored
When working with an arbitrary reader or writer, code that uses vectored
operations may end up being slower than code that copies into a single
buffer when the underlying reader or writer doesn't actually support
vectored operations. These new methods allow you to ask the reader or
witer up front if vectored operations are efficiently supported.

Currently, you have to use some heuristics to guess by e.g. checking if
the read or write only accessed the first buffer. Hyper is one concrete
example of a library that has to do this dynamically:
https://github.com/hyperium/hyper/blob/0eaf304644a396895a4ce1f0146e596640bb666a/src/proto/h1/io.rs#L582-L594
Diffstat (limited to 'src/libstd/sys/wasi/stdio.rs')
-rw-r--r--src/libstd/sys/wasi/stdio.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/libstd/sys/wasi/stdio.rs b/src/libstd/sys/wasi/stdio.rs
index 1d53884f2d6..01b041141a7 100644
--- a/src/libstd/sys/wasi/stdio.rs
+++ b/src/libstd/sys/wasi/stdio.rs
@@ -19,6 +19,11 @@ impl Stdin {
         ManuallyDrop::new(unsafe { WasiFd::from_raw(self.as_raw_fd()) }).read(data)
     }
 
+    #[inline]
+    pub fn can_read_vectored(&self) -> bool {
+        true
+    }
+
     pub fn as_raw_fd(&self) -> u32 {
         0
     }
@@ -37,6 +42,11 @@ impl Stdout {
         ManuallyDrop::new(unsafe { WasiFd::from_raw(self.as_raw_fd()) }).write(data)
     }
 
+    #[inline]
+    pub fn can_write_vectored(&self) -> bool {
+        true
+    }
+
     pub fn flush(&self) -> io::Result<()> {
         Ok(())
     }
@@ -59,6 +69,11 @@ impl Stderr {
         ManuallyDrop::new(unsafe { WasiFd::from_raw(self.as_raw_fd()) }).write(data)
     }
 
+    #[inline]
+    pub fn can_write_vectored(&self) -> bool {
+        true
+    }
+
     pub fn flush(&self) -> io::Result<()> {
         Ok(())
     }