sark-http 0.40.0

HTTP wire types, semantics, codecs, and ownership invariants for Sark
Documentation
use std::convert::Infallible;

use crate::payload::compress::inflate::{Error, Failure};

pub(super) const STEP: usize = 64 * 1024;

/// A completed work failure or a checkpoint that interrupted unfinished work.
#[derive(Debug)]
pub enum Checked<T, E> {
    Work(T),
    Check(E),
}

impl<E> Checked<Error, E> {
    pub(super) fn failed<D: From<Failure>>(self, written: usize) -> Checked<D, E> {
        match self {
            Self::Work(error) => Checked::Work(Failure::new(error, written).into()),
            Self::Check(error) => Checked::Check(error),
        }
    }
}

impl<T> Checked<T, Infallible> {
    pub fn into_work(self) -> T {
        match self {
            Self::Work(error) => error,
            Self::Check(error) => match error {},
        }
    }
}

impl<E> From<Error> for Checked<Error, E> {
    fn from(error: Error) -> Self {
        Self::Work(error)
    }
}

impl<T: From<Failure>, E> From<Failure> for Checked<T, E> {
    fn from(error: Failure) -> Self {
        Self::Work(error.into())
    }
}