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.
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.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".