pub struct Connection<R: BufRead, W: Write> { /* private fields */ }
Expand description
Use this type when you have both a reader and writer, and want them to be grouped together.
There are situations in which you have both a reader and a writer being passed around code, always kept together. This forms what is known as a ‘data clump’, and harms code readability. By grouping the two together it makes clear that they are both needed, and prevents mistakes when one is forgotten.
Connection
is internally a pair of a reader and a writer, and delegates to crate::read
and
crate::write
for Connection::read
and Connection::write
respectively.
Implementations§
Source§impl<'a> Connection<BufReader<&'a mut ChildStdout>, &'a mut ChildStdin>
impl<'a> Connection<BufReader<&'a mut ChildStdout>, &'a mut ChildStdin>
Sourcepub fn new_from_child(child: &'a mut Child) -> Option<Self>
pub fn new_from_child(child: &'a mut Child) -> Option<Self>
Creates a new Connection
that uses the stdin
of a child process as the writer and the
child process’ stdout
as the reader. This facilitates communication with this child process
by passing data into its stdin
and reading from its stdout
.
Source§impl Connection<BufReader<Stdin>, Stdout>
impl Connection<BufReader<Stdin>, Stdout>
Sourcepub fn new_from_stdio() -> Self
pub fn new_from_stdio() -> Self
Creates a new Connection
from the stdio of the current process – stdin
is used as the reader
and stdout
is used as the writer.
Source§impl<R: BufRead, W: Write> Connection<R, W>
impl<R: BufRead, W: Write> Connection<R, W>
Trait Implementations§
Source§impl<R: Clone + BufRead, W: Clone + Write> Clone for Connection<R, W>
impl<R: Clone + BufRead, W: Clone + Write> Clone for Connection<R, W>
Source§fn clone(&self) -> Connection<R, W>
fn clone(&self) -> Connection<R, W>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more