pub struct StreamDuplexer { /* private fields */ }
Expand description
An unbuffered and unlocked interactive combination input and output stream,
implementing Read
and Write
.
This may hold two file descriptors, one for reading and one for writing, such as stdin and stdout, or it may hold one file handle for both reading and writing, such as for a TCP socket.
There is no file
constructor, even though File
implements both Read
and Write
, because normal files are not interactive. However, there is a
char_device
constructor for character device files.
Implementations§
Source§impl StreamDuplexer
impl StreamDuplexer
Sourcepub fn stdin_stdout() -> Result<Self>
pub fn stdin_stdout() -> Result<Self>
Duplex with stdin and stdout, taking ownership of them.
Unlike std::io::stdin
and std::io::stdout
, this stdin_stdout
returns a stream which is unbuffered and unlocked.
This acquires a std::io::StdinLock
and a std::io::StdoutLock
(in non-recursive ways) to prevent accesses to std::io::Stdin
and
std::io::Stdout
while this is live, and fails if a StreamReader
for standard input, a StreamWriter
for standard output, or a
StreamDuplexer
for standard input and standard output already exist.
Sourcepub fn char_device(char_device: CharDevice) -> Self
Available on crate feature char-device
only.
pub fn char_device(char_device: CharDevice) -> Self
char-device
only.Duplex with an open character device, taking ownership of it.
Sourcepub fn tcp_stream<Socketlike: IntoSocketlike>(socketlike: Socketlike) -> Self
pub fn tcp_stream<Socketlike: IntoSocketlike>(socketlike: Socketlike) -> Self
Duplex with an open TCP stream, taking ownership of it.
This method can be passed a std::net::TcpStream
or similar
TcpStream
types.
Sourcepub fn unix_stream(unix_stream: UnixStream) -> Self
pub fn unix_stream(unix_stream: UnixStream) -> Self
Duplex with an open Unix-domain stream, taking ownership of it.
Sourcepub fn pipe_reader_writer(
pipe_reader: PipeReader,
pipe_writer: PipeWriter,
) -> Self
pub fn pipe_reader_writer( pipe_reader: PipeReader, pipe_writer: PipeWriter, ) -> Self
Duplex with a pair of pipe streams, taking ownership of them.
Sourcepub fn socketpair_stream(stream: SocketpairStream) -> Self
Available on non-WASI and crate feature socketpair
only.
pub fn socketpair_stream(stream: SocketpairStream) -> Self
socketpair
only.Duplex with one end of a socketpair stream, taking ownership of it.
Sourcepub fn duplex_with_command(command: Command) -> Result<Self>
pub fn duplex_with_command(command: Command) -> Result<Self>
Spawn the given command and duplex with its standard input and output.
Sourcepub fn child_stdout_stdin(
child_stdout: ChildStdout,
child_stdin: ChildStdin,
) -> Self
pub fn child_stdout_stdin( child_stdout: ChildStdout, child_stdin: ChildStdin, ) -> Self
Duplex with a child process’ stdout and stdin, taking ownership of them.
Sourcepub fn socketed_thread_read_first(
boxed_duplex: Box<dyn HalfDuplex + Send>,
) -> Result<Self>
Available on non-WASI and crate feature socketpair
only.
pub fn socketed_thread_read_first( boxed_duplex: Box<dyn HalfDuplex + Send>, ) -> Result<Self>
socketpair
only.Duplex with a duplexer from on another thread through a socketpair.
A socketpair is created, new thread is created, boxed_duplex
is
read from and written to over the socketpair.
Writes to the pipe aren’t synchronous with writes to the boxed Write
implementation. To ensure data is flushed all the way through the
thread and into the boxed Write
implementation, call flush()
, which
synchronizes with the thread to ensure that is has completed writing
all pending output.
Sourcepub fn socketed_thread_write_first(
boxed_duplex: Box<dyn HalfDuplex + Send>,
) -> Result<Self>
Available on non-WASI and crate feature socketpair
only.
pub fn socketed_thread_write_first( boxed_duplex: Box<dyn HalfDuplex + Send>, ) -> Result<Self>
socketpair
only.Duplex with a duplexer from on another thread through a socketpair.
A socketpair is created, new thread is created, boxed_duplex
is
written to and read from over the socketpair.
Writes to the pipe aren’t synchronous with writes to the boxed Write
implementation. To ensure data is flushed all the way through the
thread and into the boxed Write
implementation, call flush()
, which
synchronizes with the thread to ensure that is has completed writing
all pending output.
Sourcepub fn socketed_thread(
boxed_duplex: Box<dyn HalfDuplexReadReady + Send>,
) -> Result<Self>
Available on non-WASI and crate feature socketpair
only.
pub fn socketed_thread( boxed_duplex: Box<dyn HalfDuplexReadReady + Send>, ) -> Result<Self>
socketpair
only.Duplex with a duplexer from on another thread through a socketpair.
A socketpair is created, new thread is created, boxed_duplex
is
written to and/or read from over the socketpair.
ReadReady::num_ready_bytes
is used to determine whether to read from
or write to boxed_duplex
first. This may be inefficient, so if you
know which direction should go first, use socketed_thread_read_first
or socketed_thread_write_first
instead.
Writes to the pipe aren’t synchronous with writes to the boxed Write
implementation. To ensure data is flushed all the way through the
thread and into the boxed Write
implementation, call flush()
, which
synchronizes with the thread to ensure that is has completed writing
all pending output.
Sourcepub fn socketed_thread_func(
func: Box<dyn Send + FnOnce(SocketpairStream) -> Result<SocketpairStream>>,
) -> Result<Self>
Available on non-WASI and crate feature socketpair
only.
pub fn socketed_thread_func( func: Box<dyn Send + FnOnce(SocketpairStream) -> Result<SocketpairStream>>, ) -> Result<Self>
socketpair
only.Duplex with a function running on another thread through a socketpair.
A socketpair is created, new thread is created, func
is called in the
new thread and passed one of the ends of the socketstream.
Writes to the pipe aren’t synchronous with writes to the boxed Write
implementation. To ensure data is flushed all the way through the
thread and into the boxed Write
implementation, call flush()
, which
synchronizes with the thread to ensure that is has completed writing
all pending output.
Trait Implementations§
Source§impl AsRawReadWriteFd for StreamDuplexer
impl AsRawReadWriteFd for StreamDuplexer
Source§fn as_raw_read_fd(&self) -> RawFd
fn as_raw_read_fd(&self) -> RawFd
Source§fn as_raw_write_fd(&self) -> RawFd
fn as_raw_write_fd(&self) -> RawFd
Source§impl AsReadWriteFd for StreamDuplexer
impl AsReadWriteFd for StreamDuplexer
Source§fn as_read_fd(&self) -> BorrowedFd<'_>
fn as_read_fd(&self) -> BorrowedFd<'_>
Source§fn as_write_fd(&self) -> BorrowedFd<'_>
fn as_write_fd(&self) -> BorrowedFd<'_>
Source§impl Debug for StreamDuplexer
impl Debug for StreamDuplexer
Source§impl Peek for StreamDuplexer
impl Peek for StreamDuplexer
Source§impl Read for StreamDuplexer
impl Read for StreamDuplexer
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize>
read
, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector
)Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize>
buf
. Read moreSource§fn read_to_string(&mut self, buf: &mut String) -> Result<usize>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize>
buf
. Read moreSource§fn read_exact(&mut self, buf: &mut [u8]) -> Result<()>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<()>
buf
. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)Source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)cursor
. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read
. Read moreSource§impl ReadReady for StreamDuplexer
impl ReadReady for StreamDuplexer
Source§impl Write for StreamDuplexer
impl Write for StreamDuplexer
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)Source§fn write_all(&mut self, buf: &[u8]) -> Result<()>
fn write_all(&mut self, buf: &[u8]) -> Result<()>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<()>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<()>
write_all_vectored
)impl Duplex for StreamDuplexer
Auto Trait Implementations§
impl Freeze for StreamDuplexer
impl !RefUnwindSafe for StreamDuplexer
impl Send for StreamDuplexer
impl Sync for StreamDuplexer
impl Unpin for StreamDuplexer
impl !UnwindSafe for StreamDuplexer
Blanket Implementations§
Source§impl<T> AsRawReadWriteGrip for Twhere
T: AsRawReadWriteFd,
impl<T> AsRawReadWriteGrip for Twhere
T: AsRawReadWriteFd,
Source§fn as_raw_read_grip(&self) -> i32
fn as_raw_read_grip(&self) -> i32
Source§fn as_raw_write_grip(&self) -> i32
fn as_raw_write_grip(&self) -> i32
Source§impl<T> AsReadWriteGrip for Twhere
T: AsReadWriteFd,
impl<T> AsReadWriteGrip for Twhere
T: AsReadWriteFd,
Source§fn as_read_grip(&self) -> BorrowedFd<'_>
fn as_read_grip(&self) -> BorrowedFd<'_>
Source§fn as_write_grip(&self) -> BorrowedFd<'_>
fn as_write_grip(&self) -> BorrowedFd<'_>
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> GetSetFdFlags for T
impl<T> GetSetFdFlags for T
Source§fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
self
file descriptor.Source§fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
Source§fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>where
T: AsFilelike,
fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>where
T: AsFilelike,
self
file descriptor. Read more