Skip to content

Commit 5479fe5

Browse files
committed
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 <[email protected]>
1 parent f5418b0 commit 5479fe5

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

library/std/src/process.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,10 @@ impl Read for ChildStdout {
362362
fn is_read_vectored(&self) -> bool {
363363
self.inner.is_read_vectored()
364364
}
365+
366+
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
367+
self.inner.read_to_end(buf)
368+
}
365369
}
366370

367371
impl AsInner<AnonPipe> for ChildStdout {

library/std/src/sys/unix/pipe.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ impl AnonPipe {
5858
self.0.is_read_vectored()
5959
}
6060

61+
pub fn read_to_end(&self, buf: &mut Vec<u8>) -> io::Result<usize> {
62+
self.0.read_to_end(buf)
63+
}
64+
6165
pub fn write(&self, buf: &[u8]) -> io::Result<usize> {
6266
self.0.write(buf)
6367
}

library/std/src/sys/unsupported/pipe.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ impl AnonPipe {
1515
self.0
1616
}
1717

18+
pub fn read_to_end(&self, buf: &mut Vec<u8>) -> io::Result<usize> {
19+
self.0
20+
}
21+
1822
pub fn write(&self, _buf: &[u8]) -> io::Result<usize> {
1923
self.0
2024
}

library/std/src/sys/windows/pipe.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::os::windows::prelude::*;
22

33
use crate::ffi::OsStr;
4-
use crate::io::{self, IoSlice, IoSliceMut};
4+
use crate::io::{self, IoSlice, IoSliceMut, Read};
55
use crate::mem;
66
use crate::path::Path;
77
use crate::ptr;
@@ -261,6 +261,10 @@ impl AnonPipe {
261261
self.inner.is_read_vectored()
262262
}
263263

264+
pub fn read_to_end(&self, buf: &mut Vec<u8>) -> io::Result<usize> {
265+
self.handle().read_to_end(buf)
266+
}
267+
264268
pub fn write(&self, buf: &[u8]) -> io::Result<usize> {
265269
unsafe {
266270
let len = crate::cmp::min(buf.len(), c::DWORD::MAX as usize) as c::DWORD;

0 commit comments

Comments
 (0)