[][src]Struct jsonl::Connection

pub struct Connection<R: BufRead, W: Write> { /* fields omitted */ }

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]

pub fn new(reader: R, writer: W) -> Self[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]

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]

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]

impl<R: Ord + BufRead, W: Ord + Write> Ord for Connection<R, W>[src]

impl<R: PartialEq + BufRead, W: PartialEq + Write> PartialEq<Connection<R, W>> for Connection<R, W>[src]

impl<R: PartialOrd + BufRead, W: PartialOrd + Write> PartialOrd<Connection<R, W>> for Connection<R, W>[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]

impl<R, W> Send for Connection<R, W> where
    R: Send,
    W: Send
[src]

impl<R, W> Sync for Connection<R, W> where
    R: Sync,
    W: Sync
[src]

impl<R, W> Unpin for Connection<R, W> where
    R: Unpin,
    W: Unpin
[src]

impl<R, W> UnwindSafe for Connection<R, W> where
    R: UnwindSafe,
    W: UnwindSafe
[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.