[−][src]Struct jsonl::Connection
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
impl<R: BufRead, W: Write> Connection<R, W>
[src]
impl<'a> Connection<BufReader<&'a mut ChildStdout>, &'a mut ChildStdin>
[src]
pub fn new_from_child(child: &'a mut Child) -> Option<Self>
[src]
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
.
impl Connection<BufReader<Stdin>, Stdout>
[src]
pub fn new_from_stdio() -> Self
[src]
Creates a new Connection
from the stdio of the current process – stdin
is used as the reader
and stdout
is used as the writer.
impl Connection<BufReader<TcpStream>, TcpStream>
[src]
pub fn new_from_tcp_stream(tcp_stream: TcpStream) -> Result<Self>
[src]
Creates a new Connection
from a TCP stream.
pub fn shutdown(self) -> Result<()>
[src]
Closes the TCP stream.
impl<R: BufRead, W: Write> Connection<R, W>
[src]
pub fn read<T: DeserializeOwned>(&mut self) -> Result<T, ReadError>
[src]
Reads a line from the reader and deserializes it into a given type.
pub fn write<T: Serialize>(&mut self, t: &T) -> Result<(), WriteError>
[src]
Writes a given value to the writer, serializing it into JSON.
pub fn flush(&mut self) -> Result<()>
[src]
Flushes the contained writer’s buffer.
Trait Implementations
impl<R: Clone + BufRead, W: Clone + Write> Clone for Connection<R, W>
[src]
pub fn clone(&self) -> Connection<R, W>
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<R: Copy + BufRead, W: Copy + Write> Copy for Connection<R, W>
[src]
impl<R: Debug + BufRead, W: Debug + Write> Debug for Connection<R, W>
[src]
impl<R: Default + BufRead, W: Default + Write> Default for Connection<R, W>
[src]
pub fn default() -> Connection<R, W>
[src]
impl<R: Eq + BufRead, W: Eq + Write> Eq for Connection<R, W>
[src]
impl<R: Hash + BufRead, W: Hash + Write> Hash for Connection<R, W>
[src]
pub fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<R: Ord + BufRead, W: Ord + Write> Ord for Connection<R, W>
[src]
pub fn cmp(&self, other: &Connection<R, W>) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl<R: PartialEq + BufRead, W: PartialEq + Write> PartialEq<Connection<R, W>> for Connection<R, W>
[src]
pub fn eq(&self, other: &Connection<R, W>) -> bool
[src]
pub fn ne(&self, other: &Connection<R, W>) -> bool
[src]
impl<R: PartialOrd + BufRead, W: PartialOrd + Write> PartialOrd<Connection<R, W>> for Connection<R, W>
[src]
pub fn partial_cmp(&self, other: &Connection<R, W>) -> Option<Ordering>
[src]
pub fn lt(&self, other: &Connection<R, W>) -> bool
[src]
pub fn le(&self, other: &Connection<R, W>) -> bool
[src]
pub fn gt(&self, other: &Connection<R, W>) -> bool
[src]
pub fn ge(&self, other: &Connection<R, W>) -> bool
[src]
impl<R: BufRead, W: Write> StructuralEq for Connection<R, W>
[src]
impl<R: BufRead, W: Write> StructuralPartialEq for Connection<R, W>
[src]
Auto Trait Implementations
impl<R, W> RefUnwindSafe for Connection<R, W> where
R: RefUnwindSafe,
W: RefUnwindSafe,
[src]
R: RefUnwindSafe,
W: RefUnwindSafe,
impl<R, W> Send for Connection<R, W> where
R: Send,
W: Send,
[src]
R: Send,
W: Send,
impl<R, W> Sync for Connection<R, W> where
R: Sync,
W: Sync,
[src]
R: Sync,
W: Sync,
impl<R, W> Unpin for Connection<R, W> where
R: Unpin,
W: Unpin,
[src]
R: Unpin,
W: Unpin,
impl<R, W> UnwindSafe for Connection<R, W> where
R: UnwindSafe,
W: UnwindSafe,
[src]
R: UnwindSafe,
W: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,