saddle-runtime 0.2.0-rc.5

Saddle managed asynchronous runtime and lifecycle
Documentation
//! Internal response-framing capability shared with the approved Transport.

use std::task::{Context, Poll};

use saddle_admission::ManagedResponse;
use tokio::net::TcpStream;

use crate::compiled_route::ResponseOutcomeClass;

/// Fixed, owning write state produced from one Transport-signed framing plan.
///
/// Implementations encode and retain headers inline, then drive
/// `header -> body -> close` through the supplied unique socket. They must not
/// allocate, spawn, queue, clone the socket or reset the enclosing deadline.
#[doc(hidden)]
pub trait FixedResponseWrite: Send + Unpin + 'static {
    type Error: Send + 'static;

    fn poll_write(
        &mut self,
        socket: &mut TcpStream,
        class: ResponseOutcomeClass,
        payload: &ManagedResponse,
        context: &mut Context<'_>,
    ) -> Poll<Result<(), Self::Error>>;
}

/// Transport-owned, non-forgeable response-framing protocol.
///
/// There is deliberately no default, blanket or closure implementation and no
/// Runtime numeric plan constructor. The approved build must lock the sole
/// Transport implementation and assembly site.
#[doc(hidden)]
pub trait ResponseFramingAdapter: Send + Sync + 'static {
    type Plan: Copy + Send + Sync + Unpin + 'static;
    type Error: Send + 'static;
    type WriteState: FixedResponseWrite<Error = Self::Error>;

    fn begin(
        &self,
        plan: Self::Plan,
        payload_capacity: usize,
    ) -> Result<Self::WriteState, Self::Error>;
}