Struct PipeReader
struct PipeReader(_)
Read end of an anonymous pipe.
Implementations
impl PipeReader
fn try_clone(self: &Self) -> Result<Self>Creates a new
PipeReaderinstance that shares the same underlying file description.Examples
# #[cfg(miri)] fn main() {} # #[cfg(not(miri))] # fn main() -> std::io::Result<()> { use std::fs; use std::io::{pipe, Write}; use std::process::Command; const NUM_SLOT: u8 = 2; const NUM_PROC: u8 = 5; const OUTPUT: &str = "work.txt"; let mut jobs = vec![]; let (reader, mut writer) = pipe()?; // Write NUM_SLOT characters the pipe. writer.write_all(&[b'|'; NUM_SLOT as usize])?; // Spawn several processes that read a character from the pipe, do some work, then // write back to the pipe. When the pipe is empty, the processes block, so only // NUM_SLOT processes can be working at any given time. for _ in 0..NUM_PROC { jobs.push( Command::new("bash") .args(["-c", &format!( "read -n 1\n\ echo -n 'x' >> '{OUTPUT}'\n\ echo -n '|'", ), ]) .stdin(reader.try_clone()?) .stdout(writer.try_clone()?) .spawn()?, ); } // Wait for all jobs to finish. for mut job in jobs { job.wait()?; } // Check our work and clean up. let xs = fs::read_to_string(OUTPUT)?; fs::remove_file(OUTPUT)?; assert_eq!(xs, "x".repeat(NUM_PROC.into())); # Ok(()) # }
impl AsFd for PipeReader
fn as_fd(self: &Self) -> BorrowedFd<'_>
impl AsHandle for PipeReader
fn as_handle(self: &Self) -> BorrowedHandle<'_>
impl AsRawFd for PipeReader
fn as_raw_fd(self: &Self) -> RawFd
impl AsRawHandle for PipeReader
fn as_raw_handle(self: &Self) -> RawHandle
impl Debug for PipeReader
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result
impl Freeze for PipeReader
impl From for PipeReader
fn from(owned_handle: OwnedHandle) -> Self
impl From for PipeReader
fn from(owned_fd: OwnedFd) -> Self
impl FromRawFd for PipeReader
unsafe fn from_raw_fd(raw_fd: RawFd) -> Self
impl FromRawHandle for PipeReader
unsafe fn from_raw_handle(raw_handle: RawHandle) -> Self
impl IntoRawFd for PipeReader
fn into_raw_fd(self: Self) -> RawFd
impl IntoRawHandle for PipeReader
fn into_raw_handle(self: Self) -> RawHandle
impl Read for PipeReader
fn read(self: &mut Self, buf: &mut [u8]) -> Result<usize>fn read_vectored(self: &mut Self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize>fn is_read_vectored(self: &Self) -> boolfn read_to_end(self: &mut Self, buf: &mut Vec<u8>) -> Result<usize>fn read_buf(self: &mut Self, buf: BorrowedCursor<'_>) -> Result<()>
impl RefUnwindSafe for PipeReader
impl Send for PipeReader
impl Sync for PipeReader
impl Unpin for PipeReader
impl UnsafeUnpin for PipeReader
impl UnwindSafe for PipeReader
impl<T> Any for PipeReader
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for PipeReader
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for PipeReader
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> From for PipeReader
fn from(t: T) -> TReturns the argument unchanged.
impl<T, U> Into for PipeReader
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for PipeReader
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for PipeReader
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>