Skip to main content

ServerProtocol

Trait ServerProtocol 

Source
pub trait ServerProtocol: 'static {
    type Head<'buf>;
    type ConnState: Default + 'static;
    type CodecLayer: CodecLayer;

    const SUPPORTS_PARK: bool = false;

    // Required methods
    fn parse<'buf>(
        &self,
        state: &mut Self::ConnState,
        buf: &'buf [u8],
    ) -> Option<(Self::Head<'buf>, u32, u32)>;
    fn handle<'buf>(
        &mut self,
        req: &'buf [u8],
        head: Self::Head<'buf>,
        write: &mut [u8],
    ) -> HandlerAction;

    // Provided methods
    fn handle_park<'buf>(
        &mut self,
        conn_id: SlotId,
        conn_state: &mut Self::ConnState,
        req: &'buf [u8],
        head: Self::Head<'buf>,
        write: &mut [u8],
    ) -> ParkAction { ... }
    fn oversize_response(&self) -> &'static [u8]  { ... }
    fn route_request_body_kind(
        &self,
        head: &Self::Head<'_>,
    ) -> RouteRequestBodyKind { ... }
    fn handle_request_stream<'buf>(
        &mut self,
        head_bytes: &'buf [u8],
        head: Self::Head<'buf>,
        body_stream: RequestBodyStream,
        write: &mut [u8],
    ) -> RequestStreamAction { ... }
    fn on_register(
        &mut self,
        conn_id: SlotId,
        conn_state: &mut Self::ConnState,
    ) -> Option<Pin<Box<dyn Future<Output = ()> + 'static>>> { ... }
    fn drain_outbound(
        &mut self,
        conn_state: &mut Self::ConnState,
        write: &mut [u8],
    ) -> u32 { ... }
    fn close_pending(&self, conn_state: &Self::ConnState) -> bool { ... }
}
Expand description

Server-side protocol.

One trait owns parsing AND handling — there is no separate Framer trait or framer() accessor. Per-connection parsing state lives in ConnState; shared protocol state (rate limiters, metrics, etc.) lives in &mut self.

Head<'buf> is a GAT so parsers can return zero-copy views into buf.

Provided Associated Constants§

Source

const SUPPORTS_PARK: bool = false

Required Associated Types§

Required Methods§

Source

fn parse<'buf>( &self, state: &mut Self::ConnState, buf: &'buf [u8], ) -> Option<(Self::Head<'buf>, u32, u32)>

Try to parse one frame’s head from buf. Returns (head, head_len, body_len) on success — frame ring waits for head_len + body_len bytes total before dispatching to handle. body_len = 0 means a head-only frame.

Source

fn handle<'buf>( &mut self, req: &'buf [u8], head: Self::Head<'buf>, write: &mut [u8], ) -> HandlerAction

Provided Methods§

Source

fn handle_park<'buf>( &mut self, conn_id: SlotId, conn_state: &mut Self::ConnState, req: &'buf [u8], head: Self::Head<'buf>, write: &mut [u8], ) -> ParkAction

Source

fn oversize_response(&self) -> &'static [u8]

Source

fn route_request_body_kind(&self, head: &Self::Head<'_>) -> RouteRequestBodyKind

Source

fn handle_request_stream<'buf>( &mut self, head_bytes: &'buf [u8], head: Self::Head<'buf>, body_stream: RequestBodyStream, write: &mut [u8], ) -> RequestStreamAction

Source

fn on_register( &mut self, conn_id: SlotId, conn_state: &mut Self::ConnState, ) -> Option<Pin<Box<dyn Future<Output = ()> + 'static>>>

Source

fn drain_outbound( &mut self, conn_state: &mut Self::ConnState, write: &mut [u8], ) -> u32

Source

fn close_pending(&self, conn_state: &Self::ConnState) -> bool

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§