sark-http 0.39.0

HTTP wire types, semantics, codecs, and ownership invariants for Sark
Documentation
//! Response progress for a separately retained, append-only source.

use crate::payload::response::Method;
use core::convert::Infallible;

use crate::h1::head::{Limit, ParseError, field, response::Parts, state};

#[repr(transparent)]
pub struct State(state::State<Method>);

impl State {
    pub const fn new(request: Method, limit: Limit) -> Self {
        Self(state::State::new(request, limit))
    }

    /// # Safety
    /// Preserve the exact source prefix and nondecreasing length between reads.
    pub unsafe fn read_from<'owner, E>(
        &mut self,
        source: &'owner [u8],
    ) -> Result<Option<field::Entry<'owner>>, ParseError<E>> {
        self.0.read(source)
    }

    pub fn parts(&self) -> Option<Parts> {
        self.0.parts()
    }

    /// # Safety
    /// Preserve the exact source prefix and nondecreasing length between scans.
    pub unsafe fn scan_from(
        self,
        source: &[u8],
    ) -> Result<(Self, Option<Parts>), ParseError<Infallible>> {
        let (state, parts) = self.0.scan(source)?;
        Ok((Self(state), parts))
    }
}