pub trait FilterLayer: Debug + 'static {
// Required methods
fn process_read_buf(&self, buf: &FilterBuf<'_>) -> Result<(), Error>;
fn process_write_buf(&self, buf: &FilterBuf<'_>) -> Result<(), Error>;
// Provided methods
fn query(&self, id: TypeId) -> Option<Box<dyn Any>> { ... }
fn shutdown(&self, buf: &FilterBuf<'_>) -> Result<Poll<()>, Error> { ... }
}Expand description
A processing layer that transforms an I/O stream’s read and write buffers.
Read processing runs from the transport toward the application. Write and shutdown processing run from the application toward the transport. Each callback receives the buffers immediately before and after this layer.
Implementations must move or transform all bytes they consume. Bytes left in a source buffer remain available to the layer on a later callback.
Required Methods§
Sourcefn process_read_buf(&self, buf: &FilterBuf<'_>) -> Result<(), Error>
fn process_read_buf(&self, buf: &FilterBuf<'_>) -> Result<(), Error>
Processes incoming data from the transport-facing source buffer into the application-facing destination buffer.
This is also called once after clean transport read EOF, with
IoRef::is_read_eof returning true.
Sourcefn process_write_buf(&self, buf: &FilterBuf<'_>) -> Result<(), Error>
fn process_write_buf(&self, buf: &FilterBuf<'_>) -> Result<(), Error>
Processes outgoing data from the application-facing source buffer into the transport-facing destination buffer.
A filter may leave source data in place, for example while a TLS
handshake is in progress. The transport write task then pauses, and
this is called again once new output is queued or new input has been
processed. A filter that waits for anything else wakes the read task
through Filter::poll_ready, its output is processed again once the
chain is ready.
Provided Methods§
Sourcefn query(&self, id: TypeId) -> Option<Box<dyn Any>>
fn query(&self, id: TypeId) -> Option<Box<dyn Any>>
Returns type-indexed information exposed by this layer.
Returning None allows the query to continue through the remaining
filter chain.
Sourcefn shutdown(&self, buf: &FilterBuf<'_>) -> Result<Poll<()>, Error>
fn shutdown(&self, buf: &FilterBuf<'_>) -> Result<Poll<()>, Error>
Performs graceful filter shutdown.
Returning Poll::Pending keeps the filter active and causes shutdown to
be polled again after the I/O task is notified. A ready result allows
shutdown to continue toward the transport.
A filter that waits for input from the peer must check
IoRef::is_read_eof and return a ready result once it is set: after a
clean read EOF no further input can arrive, so pending forever would
only stall the close until the shutdown timeout expires. The runtime
also ends the shutdown phase itself in that case, but it cannot know
whether the filter considers the shutdown complete.
Once this returns a ready result, process_write_buf
runs one final time and the layer is finished. Output still left in
the layer’s write source after that pass is discarded and shutdown
fails with an error reporting the lost byte count. The default
implementation is ready immediately, so a filter that retains output
(for example until a handshake completes) must override this method
and return Poll::Pending until that output has been processed.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".