InboundPipeline

Trait InboundPipeline 

Source
pub trait InboundPipeline<R> {
    // Required methods
    fn transport_active(&self);
    fn transport_inactive(&self);
    fn handle_read(&self, msg: R);
    fn poll_write(&self) -> Option<R>;
    fn handle_timeout(&self, now: Instant);
    fn poll_timeout(&self, eto: &mut Instant);
    fn handle_eof(&self);
    fn handle_error(&self, err: Box<dyn Error>);
}
Expand description

Pipeline traits for inbound and outbound message processing Inbound operations for a pipeline.

The InboundPipeline trait defines operations for pushing data and events into the pipeline (from the network/transport toward the application).

These methods are typically called by your I/O layer when:

  • Data arrives from the network
  • Connection state changes
  • Timeouts occur
  • Errors happen

§Type Parameters

  • R: The input message type (what you push into the pipeline)

§Example

use sansio::{Pipeline, InboundPipeline, Handler, Context};
use std::time::Instant;

// Simple pass-through handler for the example
struct SimpleHandler;
impl Handler for SimpleHandler {
    type Rin = Vec<u8>;
    type Rout = String;
    type Win = String;
    type Wout = Vec<u8>;
    fn name(&self) -> &str { "SimpleHandler" }
    fn handle_read(&mut self, ctx: &Context<Self::Rin, Self::Rout, Self::Win, Self::Wout>, msg: Self::Rin) {
        // Convert Vec<u8> to String
        if let Ok(s) = String::from_utf8(msg) {
            ctx.fire_handle_read(s);
        }
    }
    fn poll_write(&mut self, ctx: &Context<Self::Rin, Self::Rout, Self::Win, Self::Wout>) -> Option<Self::Wout> {
        // Convert String to Vec<u8>
        ctx.fire_poll_write().map(|s| s.into_bytes())
    }
}

let pipeline: Pipeline<Vec<u8>, String> = Pipeline::new();
pipeline.add_back(SimpleHandler);
let pipeline = pipeline.finalize();

// Push data into the pipeline
pipeline.transport_active();
pipeline.handle_read(vec![72, 101, 108, 108, 111]); // "Hello"
pipeline.handle_timeout(Instant::now());

Required Methods§

Source

fn transport_active(&self)

Notifies the pipeline that the transport is active (connected).

Call this when a connection is established. The event will propagate through all handlers in the pipeline.

Source

fn transport_inactive(&self)

Notifies the pipeline that the transport is inactive (disconnected).

Call this when a connection is closed. The event will propagate through all handlers in the pipeline.

Source

fn handle_read(&self, msg: R)

Pushes an incoming message into the pipeline.

The message will flow through handlers from first to last, with each handler potentially transforming it.

§Parameters
  • msg: The incoming message (type R)
Source

fn poll_write(&self) -> Option<R>

Polls the pipeline for an outgoing message.

This retrieves messages that should be sent over the transport. Messages flow from last handler to first (outbound direction).

§Returns
  • Some(R): A message ready to send
  • None: No message available
Source

fn handle_timeout(&self, now: Instant)

Handles a timeout event.

Call this periodically or when a timeout fires. Handlers can use this to perform time-based operations (keepalives, retransmissions, etc.).

§Parameters
  • now: The current timestamp
Source

fn poll_timeout(&self, eto: &mut Instant)

Polls for the next timeout deadline.

Updates eto to the earliest time any handler needs handle_timeout called. Use this to set your I/O timer.

§Parameters
  • eto: Mutable reference to earliest timeout. Will be updated to the minimum across all handlers.
Source

fn handle_eof(&self)

Handles an end-of-file event.

Call this when the input stream is closed (e.g., TCP FIN received).

Source

fn handle_error(&self, err: Box<dyn Error>)

Handles an error event.

Call this when an error occurs in I/O or processing.

§Parameters
  • err: The error to propagate through the pipeline

Implementors§

Source§

impl<R: 'static, W: 'static> InboundPipeline<R> for Pipeline<R, W>