Skip to content

Commit

Permalink
Implement Read/Write for &pipe::Sender/&pipe::Receiver
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomasdezeeuw committed Dec 3, 2020
1 parent 9c438c7 commit 1be481d
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/sys/unix/pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,20 @@ impl Write for Sender {
}
}

impl Write for &Sender {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
self.inner.do_io(|sender| (&*sender).write(buf))
}

fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
self.inner.do_io(|sender| (&*sender).write_vectored(bufs))
}

fn flush(&mut self) -> io::Result<()> {
self.inner.do_io(|sender| (&*sender).flush())
}
}

/// # Notes
///
/// The underlying pipe is **not** set to non-blocking.
Expand Down Expand Up @@ -333,6 +347,16 @@ impl Read for Receiver {
}
}

impl Read for &Receiver {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
self.inner.do_io(|sender| (&*sender).read(buf))
}

fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
self.inner.do_io(|sender| (&*sender).read_vectored(bufs))
}
}

/// # Notes
///
/// The underlying pipe is **not** set to non-blocking.
Expand Down

0 comments on commit 1be481d

Please sign in to comment.