diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2019-04-10 12:51:25 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2019-04-10 12:51:25 -0700 |
| commit | acf3ddb5ad163ea98f8935b045fc6d15faefa454 (patch) | |
| tree | 14259cccc6d6a15409cc06a033bd459a0766eb43 /src/libstd/sys/wasi/stdio.rs | |
| parent | 3750348daff89741e3153e0e120aa70a45ff5b68 (diff) | |
| download | rust-acf3ddb5ad163ea98f8935b045fc6d15faefa454.tar.gz rust-acf3ddb5ad163ea98f8935b045fc6d15faefa454.zip | |
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.
Diffstat (limited to 'src/libstd/sys/wasi/stdio.rs')
| -rw-r--r-- | src/libstd/sys/wasi/stdio.rs | 18 |
1 files changed, 15 insertions, 3 deletions
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<usize> { + self.read_vectored(&mut [IoVecMut::new(data)]) + } + + pub fn read_vectored(&self, data: &mut [IoVecMut<'_>]) -> io::Result<usize> { 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<usize> { + self.write_vectored(&[IoVec::new(data)]) + } + + pub fn write_vectored(&self, data: &[IoVec<'_>]) -> io::Result<usize> { 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<usize> { + self.write_vectored(&[IoVec::new(data)]) + } + + pub fn write_vectored(&self, data: &[IoVec<'_>]) -> io::Result<usize> { ManuallyDrop::new(unsafe { WasiFd::from_raw(libc::STDERR_FILENO as u32) }) - .write(&[IoVec::new(data)]) + .write(data) } pub fn flush(&self) -> io::Result<()> { |
