From acf3ddb5ad163ea98f8935b045fc6d15faefa454 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 10 Apr 2019 12:51:25 -0700 Subject: std: Add `{read,write}_vectored` for more types This commit implements the `{read,write}_vectored` methods on more types in the standard library, namely: * `std::fs::File` * `std::process::ChildStd{in,out,err}` * `std::io::Std{in,out,err}` * `std::io::Std{in,out,err}Lock` * `std::io::Std{in,out,err}Raw` Where supported the OS implementations hook up to native support, otherwise it falls back to the already-defaulted implementation. --- src/libstd/sys/wasi/pipe.rs | 10 +++++++++- src/libstd/sys/wasi/stdio.rs | 18 +++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) (limited to 'src/libstd/sys/wasi') diff --git a/src/libstd/sys/wasi/pipe.rs b/src/libstd/sys/wasi/pipe.rs index 2582b993b60..aa6bf8076f6 100644 --- a/src/libstd/sys/wasi/pipe.rs +++ b/src/libstd/sys/wasi/pipe.rs @@ -1,4 +1,4 @@ -use crate::io; +use crate::io::{self, IoVec, IoVecMut}; use crate::sys::Void; pub struct AnonPipe(Void); @@ -8,10 +8,18 @@ impl AnonPipe { match self.0 {} } + pub fn read_vectored(&self, _bufs: &mut [IoVecMut<'_>]) -> io::Result { + match self.0 {} + } + pub fn write(&self, _buf: &[u8]) -> io::Result { match self.0 {} } + pub fn write_vectored(&self, _bufs: &[IoVec<'_>]) -> io::Result { + match self.0 {} + } + pub fn diverge(&self) -> ! { match self.0 {} } diff --git a/src/libstd/sys/wasi/stdio.rs b/src/libstd/sys/wasi/stdio.rs index 19294788666..bdad4084891 100644 --- a/src/libstd/sys/wasi/stdio.rs +++ b/src/libstd/sys/wasi/stdio.rs @@ -13,8 +13,12 @@ impl Stdin { } pub fn read(&self, data: &mut [u8]) -> io::Result { + self.read_vectored(&mut [IoVecMut::new(data)]) + } + + pub fn read_vectored(&self, data: &mut [IoVecMut<'_>]) -> io::Result { ManuallyDrop::new(unsafe { WasiFd::from_raw(libc::STDIN_FILENO as u32) }) - .read(&mut [IoVecMut::new(data)]) + .read(data) } } @@ -24,8 +28,12 @@ impl Stdout { } pub fn write(&self, data: &[u8]) -> io::Result { + self.write_vectored(&[IoVec::new(data)]) + } + + pub fn write_vectored(&self, data: &[IoVec<'_>]) -> io::Result { ManuallyDrop::new(unsafe { WasiFd::from_raw(libc::STDOUT_FILENO as u32) }) - .write(&[IoVec::new(data)]) + .write(data) } pub fn flush(&self) -> io::Result<()> { @@ -39,8 +47,12 @@ impl Stderr { } pub fn write(&self, data: &[u8]) -> io::Result { + self.write_vectored(&[IoVec::new(data)]) + } + + pub fn write_vectored(&self, data: &[IoVec<'_>]) -> io::Result { ManuallyDrop::new(unsafe { WasiFd::from_raw(libc::STDERR_FILENO as u32) }) - .write(&[IoVec::new(data)]) + .write(data) } pub fn flush(&self) -> io::Result<()> { -- cgit 1.4.1-3-g733a5