Trait Pipe

Source
pub trait Pipe: Sized {
    type Reader: PipeRead<Self>;
    type Writer: PipeWrite<Self>;

    // Required method
    fn pipe(&mut self, input: &[u8]) -> (usize, Option<Vec<u8>>);

    // Provided methods
    fn reader(self, inner: Box<dyn Read>) -> Self::Reader { ... }
    fn writer(self, inner: Box<dyn Write>) -> Self::Writer { ... }
    fn pipe_transparent(&self, input: &[u8]) -> (usize, Option<Vec<u8>>) { ... }
}
Expand description

Something that can pipe given data.

A pipe may monitor, but also transform data flowing through it.

From this pipe, a reader or writer can be created using the corresponding reader and writer functions to wrap an existing reader or writer.

Required Associated Types§

Source

type Reader: PipeRead<Self>

The wrapping reader type used for this pipe.

Source

type Writer: PipeWrite<Self>

The wrapping writer type used for this pipe.

Required Methods§

Source

fn pipe(&mut self, input: &[u8]) -> (usize, Option<Vec<u8>>)

Pipe bytes from input, monitor/transform it, return the output.

This should not be used directly, and is automatically used by a PipeRead or PipeWrite object for the actual piping.

This returns a tuple with the number of bytes read from the input, along with transformed data if available in the following format: (read_bytes, transformed_data).

Pipes that just monitor data, immediately return the input. The pipe_transparent helper function can be used for this inside the implementation.

Provided Methods§

Source

fn reader(self, inner: Box<dyn Read>) -> Self::Reader

Wrap the inner reader, bytes that are read are transformed through this pipe.

Source

fn writer(self, inner: Box<dyn Write>) -> Self::Writer

Wrap the inner writer, bytes that are read are transformed through this pipe.

Source

fn pipe_transparent(&self, input: &[u8]) -> (usize, Option<Vec<u8>>)

Transparently pipe input by immediately returning it.

This should not be used directly, and is automatically used by a PipeRead or PipeWrite object for the actual piping.

This can be used as helper function inside the pipe function if data is only monitored and not transformed.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§