Struct io_streams::StreamDuplexer [−][src]
pub struct StreamDuplexer { /* fields omitted */ }
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
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.
This is supported on crate feature char-device
only.
char-device
only.Duplex with an open character device, taking ownership of it.
Duplex with an open TCP stream, taking ownership of it.
This method can be passed a std::net::TcpStream
or similar
TcpStream
types.
Duplex with an open Unix-domain stream, taking ownership of it.
Duplex with a pair of pipe streams, taking ownership of them.
This is supported on non-WASI and crate feature socketpair
only.
socketpair
only.Duplex with one end of a socketpair stream, taking ownership of it.
Spawn the given command and duplex with its standard input and output.
Duplex with a child process’ stdout and stdin, taking ownership of them.
This is supported on non-WASI and crate feature socketpair
only.
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.
This is supported on non-WASI and crate feature socketpair
only.
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.
This is supported on non-WASI and crate feature socketpair
only.
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.
pub fn socketed_thread_func(
func: Box<dyn Send + FnOnce(SocketpairStream) -> Result<SocketpairStream>>
) -> Result<Self>
This is supported 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
Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more
Like read
, except that it reads into a slice of buffers. Read more
can_vector
)Determines if this Read
er has an efficient read_vectored
implementation. Read more
Read all bytes until EOF in this source, placing them into buf
. Read more
Read all bytes until EOF in this source, appending them to buf
. Read more
Read the exact number of bytes required to fill buf
. Read more
read_buf
)Pull some bytes from this source into the specified buffer. Read more
read_buf
)Read the exact number of bytes required to fill buf
. Read more
Creates a “by reference” adaptor for this instance of Read
. Read more
Creates an adapter which will chain this stream with another. Read more
Return the number of bytes which are ready to be read immediately.
Write a buffer into this writer, returning how many bytes were written. Read more
Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
can_vector
)Determines if this Write
r has an efficient write_vectored
implementation. Read more
Attempts to write an entire buffer into this writer. Read more
write_all_vectored
)Attempts to write multiple buffers into this writer. Read more
Writes a formatted string into this writer, returning any error encountered. Read more
Auto Trait Implementations
impl !RefUnwindSafe for StreamDuplexer
impl Send for StreamDuplexer
impl Sync for StreamDuplexer
impl Unpin for StreamDuplexer
impl !UnwindSafe for StreamDuplexer
Blanket Implementations
Mutably borrows from an owned value. Read more
Query the “status” flags for the self
file descriptor.
pub fn new_set_fd_flags(
&self,
fd_flags: FdFlags
) -> Result<SetFdFlags<T>, Error> where
T: AsFilelike,
pub fn new_set_fd_flags(
&self,
fd_flags: FdFlags
) -> Result<SetFdFlags<T>, Error> where
T: AsFilelike,
Create a new SetFdFlags
value for use with set_fd_flags
. Read more
pub fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error> where
T: AsFilelike,
pub fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error> where
T: AsFilelike,
Set the “status” flags for the self
file descriptor. Read more