sark-http 0.40.0

HTTP wire types, semantics, codecs, and ownership invariants for Sark
Documentation
use core::ops;

use o3::buffer::pool;

use crate::{
    field::metadata::{
        packed,
        section::{
            rules,
            state::{RetainedHead, decode::Head},
            storage::{self, Block},
        },
    },
    request::{Bound, Error, Layout, Source},
};

/// Consumes the exact retained request admission and its immutable owner.
pub trait Bind: Sized {
    type Owner: Source;

    /// # Safety
    /// Use the sealed native head and its closed policy. Each range must be the exact
    /// committed value of the corresponding wire field in this head's immutable storage.
    unsafe fn try_bind(
        self,
        path: Option<ops::Range<usize>>,
        path_len: Option<usize>,
        pseudo: Option<ops::Range<usize>>,
        host: Option<ops::Range<usize>>,
    ) -> Result<Bound<Self::Owner>, Error>;
}

impl<const PREFIX: usize, S: rules::RawSelection> Bind for Head<rules::RetainRaw<PREFIX, S>> {
    type Owner = packed::Decoded<pool::Span, PREFIX>;

    unsafe fn try_bind(
        self,
        path: Option<ops::Range<usize>>,
        path_len: Option<usize>,
        pseudo: Option<ops::Range<usize>>,
        host: Option<ops::Range<usize>>,
    ) -> Result<Bound<Self::Owner>, Error> {
        let (owner, _, plan) = self.into_parts();
        let layout = Layout::from_kept(owner.as_bytes(), path, path_len, pseudo, host, plan)?;
        Ok(Bound { owner, layout })
    }
}

impl<S> Bind for RetainedHead<storage::Fields, S> {
    type Owner = storage::Bytes;

    unsafe fn try_bind(
        self,
        path: Option<ops::Range<usize>>,
        path_len: Option<usize>,
        pseudo: Option<ops::Range<usize>>,
        host: Option<ops::Range<usize>>,
    ) -> Result<Bound<Self::Owner>, Error> {
        let (fields, _, plan) = self.into_parts();
        let owner = fields.into_bytes();
        let layout = Layout::from_kept(owner.as_ref(), path, path_len, pseudo, host, plan)?;
        Ok(Bound { owner, layout })
    }
}