diff options
| author | Ayush Singh <ayushsingh1325@gmail.com> | 2022-12-08 18:12:15 +0530 |
|---|---|---|
| committer | Ayush Singh <ayushsingh1325@gmail.com> | 2022-12-08 18:12:15 +0530 |
| commit | 5479fe5f70bb32f037ff97de03ed185bdf2f54b7 (patch) | |
| tree | fdc635e201ef6e372a3b30ea7e825a61ca9fef56 /library/std/src | |
| parent | f5418b09e84883c4de2e652a147ab9faff4eee29 (diff) | |
| download | rust-5479fe5f70bb32f037ff97de03ed185bdf2f54b7.tar.gz rust-5479fe5f70bb32f037ff97de03ed185bdf2f54b7.zip | |
Add read_to_end for AnonPipe
Add `read_to_end` method for `sys::{target}::pipe::AnonPipe`. This allows
having a more optimized version of `read_to_end` for ChildStdout.
Signed-off-by: Ayush Singh <ayushsingh1325@gmail.com>
Diffstat (limited to 'library/std/src')
| -rw-r--r-- | library/std/src/process.rs | 4 | ||||
| -rw-r--r-- | library/std/src/sys/unix/pipe.rs | 4 | ||||
| -rw-r--r-- | library/std/src/sys/unsupported/pipe.rs | 4 | ||||
| -rw-r--r-- | library/std/src/sys/windows/pipe.rs | 6 |
4 files changed, 17 insertions, 1 deletions
diff --git a/library/std/src/process.rs b/library/std/src/process.rs index 400d25beb26..1ff7bba85d2 100644 --- a/library/std/src/process.rs +++ b/library/std/src/process.rs @@ -362,6 +362,10 @@ impl Read for ChildStdout { fn is_read_vectored(&self) -> bool { self.inner.is_read_vectored() } + + fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> { + self.inner.read_to_end(buf) + } } impl AsInner<AnonPipe> for ChildStdout { diff --git a/library/std/src/sys/unix/pipe.rs b/library/std/src/sys/unix/pipe.rs index a56c275c942..a744d0ab640 100644 --- a/library/std/src/sys/unix/pipe.rs +++ b/library/std/src/sys/unix/pipe.rs @@ -58,6 +58,10 @@ impl AnonPipe { self.0.is_read_vectored() } + pub fn read_to_end(&self, buf: &mut Vec<u8>) -> io::Result<usize> { + self.0.read_to_end(buf) + } + pub fn write(&self, buf: &[u8]) -> io::Result<usize> { self.0.write(buf) } diff --git a/library/std/src/sys/unsupported/pipe.rs b/library/std/src/sys/unsupported/pipe.rs index 25514c2322f..75ce7546796 100644 --- a/library/std/src/sys/unsupported/pipe.rs +++ b/library/std/src/sys/unsupported/pipe.rs @@ -15,6 +15,10 @@ impl AnonPipe { self.0 } + pub fn read_to_end(&self, buf: &mut Vec<u8>) -> io::Result<usize> { + self.0 + } + pub fn write(&self, _buf: &[u8]) -> io::Result<usize> { self.0 } diff --git a/library/std/src/sys/windows/pipe.rs b/library/std/src/sys/windows/pipe.rs index 9f26acc4520..7b25edaa556 100644 --- a/library/std/src/sys/windows/pipe.rs +++ b/library/std/src/sys/windows/pipe.rs @@ -1,7 +1,7 @@ use crate::os::windows::prelude::*; use crate::ffi::OsStr; -use crate::io::{self, IoSlice, IoSliceMut}; +use crate::io::{self, IoSlice, IoSliceMut, Read}; use crate::mem; use crate::path::Path; use crate::ptr; @@ -261,6 +261,10 @@ impl AnonPipe { self.inner.is_read_vectored() } + pub fn read_to_end(&self, buf: &mut Vec<u8>) -> io::Result<usize> { + self.handle().read_to_end(buf) + } + pub fn write(&self, buf: &[u8]) -> io::Result<usize> { unsafe { let len = crate::cmp::min(buf.len(), c::DWORD::MAX as usize) as c::DWORD; |
