sark-http 0.40.0

HTTP wire types, semantics, codecs, and ownership invariants for Sark
Documentation
mod overflow;

pub use overflow::Overflow;

use crate::{
    field,
    payload::response::{Encode, encoded, headers, status},
};
use std::convert::Infallible;

pub trait Reply {
    type Status: status::Source;
    type Body: encoded::Source<true>;

    fn into_parts(
        self,
    ) -> (
        <Self::Status as status::Source>::Value,
        impl field::Source<headers::Application> + Copy,
        Self::Body,
    );
}

impl Reply for (status::Code, (), Infallible) {
    type Status = status::Code;
    type Body = Infallible;

    fn into_parts(
        self,
    ) -> (
        status::Code,
        impl field::Source<headers::Application> + Copy,
        Self::Body,
    ) {
        self
    }
}

impl Body for Infallible {
    fn encoded_len(&self) -> usize {
        match *self {}
    }
}

pub trait Body: Encode {
    fn encoded_len(&self) -> usize;
}

/// An encoder whose size must be admitted before transport output is prepared.
pub trait TryBody: Encode {
    fn try_len(&self) -> Result<usize, Overflow>;
}

impl<B: Body> TryBody for B {
    fn try_len(&self) -> Result<usize, Overflow> {
        Ok(self.encoded_len())
    }
}