1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//! 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>;
}