Skip to content

Commit

Permalink
Add read_to_end for AnonPipe
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Ayush1325 committed Dec 8, 2022
1 parent 97fec55 commit 025c3d4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions std/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions std/src/sys/unix/pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 4 additions & 0 deletions std/src/sys/unsupported/pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 5 additions & 1 deletion std/src/sys/windows/pipe.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 025c3d4

Please sign in to comment.