about summary refs log tree commit diff
path: root/src/libstd/fs.rs
diff options
context:
space:
mode:
authorDylan DPC <dylan.dpc@gmail.com>2020-04-27 22:14:55 +0200
committerGitHub <noreply@github.com>2020-04-27 22:14:55 +0200
commitc4d9f42f6d29b9c7bf8f6ca98be02621724cb9d2 (patch)
treefaf85c1d2ef5b674504ce069afa249e1f4e22b31 /src/libstd/fs.rs
parent46ec74e60f238f694b46c976d6217e7cf8d4cf1a (diff)
parentc68f23ff6d670e579e0951352e20a1495b66fce0 (diff)
downloadrust-c4d9f42f6d29b9c7bf8f6ca98be02621724cb9d2.tar.gz
rust-c4d9f42f6d29b9c7bf8f6ca98be02621724cb9d2.zip
Rollup merge of #67841 - sfackler:can-vector, r=Amaneiu
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/fs.rs')
-rw-r--r--src/libstd/fs.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs
index 119bdfcb0f4..f4c164a324e 100644
--- a/src/libstd/fs.rs
+++ b/src/libstd/fs.rs
@@ -660,6 +660,11 @@ impl Read for File {
     }
 
     #[inline]
+    fn is_read_vectored(&self) -> bool {
+        self.inner.is_read_vectored()
+    }
+
+    #[inline]
     unsafe fn initializer(&self) -> Initializer {
         Initializer::nop()
     }
@@ -674,6 +679,11 @@ impl Write for File {
         self.inner.write_vectored(bufs)
     }
 
+    #[inline]
+    fn is_write_vectored(&self) -> bool {
+        self.inner.is_write_vectored()
+    }
+
     fn flush(&mut self) -> io::Result<()> {
         self.inner.flush()
     }
@@ -695,6 +705,11 @@ impl Read for &File {
     }
 
     #[inline]
+    fn is_read_vectored(&self) -> bool {
+        self.inner.is_read_vectored()
+    }
+
+    #[inline]
     unsafe fn initializer(&self) -> Initializer {
         Initializer::nop()
     }
@@ -709,6 +724,11 @@ impl Write for &File {
         self.inner.write_vectored(bufs)
     }
 
+    #[inline]
+    fn is_write_vectored(&self) -> bool {
+        self.inner.is_write_vectored()
+    }
+
     fn flush(&mut self) -> io::Result<()> {
         self.inner.flush()
     }