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§
Required Methods§
Sourcefn pipe(&mut self, input: &[u8]) -> (usize, Option<Vec<u8>>)
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§
Sourcefn reader(self, inner: Box<dyn Read>) -> Self::Reader
fn reader(self, inner: Box<dyn Read>) -> Self::Reader
Wrap the inner
reader, bytes that are read are transformed through this pipe.
Sourcefn writer(self, inner: Box<dyn Write>) -> Self::Writer
fn writer(self, inner: Box<dyn Write>) -> Self::Writer
Wrap the inner
writer, bytes that are read are transformed through this pipe.
Sourcefn pipe_transparent(&self, input: &[u8]) -> (usize, Option<Vec<u8>>)
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.