sark 0.13.0

Simple Asynchronous Rust webKit - Server
Documentation
use dope_fiber::abi::Fiber;
use sark_core::http::body_kind::ResponseKind;
use sark_core::http::{IntoResponseShape, Shape, ShapeKind, ShapeMetadata, ShapeStream};

pub type NativeStream = sark_core::http::StreamShape;
pub type Sync = sark_core::http::SyncShape;

use super::spec::RouteSpec;
use crate::request;

pub struct NativeFiber;

pub trait NativeResponse<'req>: Sized {
    type Kind;
    type Shape: Shape<'req>;
    type Stream: 'static;

    const BODY_KIND: ResponseKind =
        <<Self::Shape as Shape<'req>>::Metadata as ShapeMetadata>::BODY_KIND;

    fn into_route_response(self) -> Self::Shape;
}

impl<'req, R> NativeResponse<'req> for R
where
    R: IntoResponseShape<'req>,
{
    type Kind = ShapeKind<'req, R::Shape>;
    type Shape = R::Shape;
    type Stream = ShapeStream<'req, R::Shape>;

    fn into_route_response(self) -> Self::Shape {
        self.into_response_shape()
    }
}

pub trait Route<State>: RouteSpec {
    fn invoke<'req, 'a>(
        params: <Self as RouteSpec>::Params<'req>,
        req: &request::Ref<'req>,
        headers: <Self as RouteSpec>::Headers<'req>,
        parsed_body: <Self as RouteSpec>::ParsedBody<'req>,
        state: &'a State,
    ) -> <Self as RouteSpec>::Response<'req>
    where
        'req: 'a;
}

pub trait TaskRoute<'d, State>: RouteSpec + Sized {
    fn invoke_task<'req>(
        storage: request::RequestStorage,
        raw_params: <Self as RouteSpec>::RawParams,
        raw_headers: <Self as RouteSpec>::RawHeaders,
        target: std::ops::Range<usize>,
        state: &'req State,
        timer: &'req crate::Timer<'d>,
    ) -> impl Fiber<'d, Output = Result<Self::AsyncResponse, &'static [u8]>> + 'req
    where
        State: 'req,
        'd: 'req;
}