sark-http 0.40.0

HTTP wire types, semantics, codecs, and ownership invariants for Sark
Documentation
use o3::depot::map::compact;

use crate::payload::compress::dynamic::index::State;

struct Directory<'a> {
    layout: &'a compact::Layout,
    bytes: &'a mut [u8],
}

/// # Safety
/// `bytes` must be this state's initialized directory plane. Retire the indexed
/// records before exposing the owner again.
pub(in crate::payload::compress::dynamic) unsafe fn reset(index: &State, bytes: &mut [u8]) {
    let mut plane = Directory {
        layout: &index.name,
        bytes,
    };
    // SAFETY: reset holds the exclusive plane across both directory writes.
    unsafe { compact::raw::Write::clear(&mut plane) };
    plane.layout = &index.exact;
    // SAFETY: the exact directory occupies its own region of the same plane.
    unsafe { compact::raw::Write::clear(&mut plane) };
}

// SAFETY: only reset pairs either admitted layout with its original plane.
unsafe impl compact::raw::Read for Directory<'_> {
    fn layout(&self) -> compact::Layout {
        *self.layout
    }

    fn bytes(&self) -> &[u8] {
        self.bytes
    }
}

// SAFETY: the exclusive borrow covers exactly the bytes returned by Read.
unsafe impl compact::raw::Write for Directory<'_> {
    unsafe fn bytes_mut(&mut self) -> &mut [u8] {
        self.bytes
    }
}