Skip to main content

Filter

Trait Filter 

Source
pub trait Filter: 'static {
    // Required methods
    fn query(&self, id: TypeId) -> Option<Box<dyn Any>>;
    fn process_read_buf(&self, ctx: &mut FilterCtx<'_>) -> Result<(), Error>;
    fn process_write_buf(&self, ctx: &mut FilterCtx<'_>) -> Result<(), Error>;
    fn shutdown(&self, ctx: &mut FilterCtx<'_>) -> Result<Poll<()>, Error>;
    fn poll_ready(&self, cx: &mut Context<'_>) -> Poll<Result<(), Error>>;
}
Expand description

Complete filter-chain interface used by Io.

Most filters should implement FilterLayer and be installed with Io::add_filter. Implement this trait directly only when wrapping or replacing a complete chain.

Required Methods§

Source

fn query(&self, id: TypeId) -> Option<Box<dyn Any>>

Returns type-indexed information exposed by this chain.

Source

fn process_read_buf(&self, ctx: &mut FilterCtx<'_>) -> Result<(), Error>

Processes incoming data from the transport toward the application.

Source

fn process_write_buf(&self, ctx: &mut FilterCtx<'_>) -> Result<(), Error>

Processes outgoing data from the application toward the transport.

Source

fn shutdown(&self, ctx: &mut FilterCtx<'_>) -> Result<Poll<()>, Error>

Performs graceful shutdown from the outermost layer toward the transport.

Source

fn poll_ready(&self, cx: &mut Context<'_>) -> Poll<Result<(), Error>>

Checks whether the chain is ready to process more input.

This is polled by the transport read task only, a chain that is not ready pauses transport reads until it wakes the task given in cx. The dispatcher is notified when the pause starts and when it ends, see IoRef::is_filter_paused. Once the chain is ready again, input and output it holds are processed again without waiting for new transport input. A chain that stops being ready between polls is only observed by the next poll, it can wake the task given to the previous one.

Transport writes are not paused, output that reached the transport is always delivered. A filter that is not ready to produce output keeps it in its own buffers instead, see FilterLayer::process_write_buf. A filter that waits for input from the peer, for example during a TLS handshake, must not report Pending here, that input would never be read.

Graceful shutdown and its deadline do not depend on the chain being ready. An error ends the connection like any filter error: the chain is not called again and its shutdown is skipped, output that reached the transport is still delivered within the shutdown deadline.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl Filter for Base

Source§

impl Filter for Sealed

Source§

impl<F, L> Filter for Layer<F, L>
where F: FilterLayer, L: Filter,