dope-core 0.77.0

Owned native I/O and completion driver for dope
Documentation
use std::marker;

use o3::depot;

use crate::driver::{
    self,
    receive::credit::{Slot, Wake, error, storage},
    route::indices,
    schedule::ready,
};

/// Fixed retained-credit storage owned by one driver generation.
pub struct Storage<'d> {
    pub(in crate::driver) entries: storage::Slots<'d, ready::Stored, Wake, ready::Arena>,
    pub(in crate::driver::receive::credit) driver: driver::Invariant<'d>,
}

impl<'d> Storage<'d> {
    /// Checks the index once and borrows its exact active storage generation.
    pub fn get(&self, index: indices::SlotIndex) -> Result<Slot<'_, 'd>, error::Index> {
        Ok(Slot {
            entry: self.entries.get(index)?,
            driver: self.driver,
        })
    }
}

// SAFETY: the borrow retains the original active group and its exact driver.
unsafe impl<'a, 'd> depot::raw::Project<usize> for &'a Storage<'d> {
    type Output = Slot<'a, 'd>;

    unsafe fn project(self, index: usize) -> Self::Output {
        // SAFETY: the caller proves this index is in the logical prefix of the original block.
        let entry = unsafe { self.entries.block.as_slice().get_unchecked(index) };
        Slot {
            entry: storage::Slot {
                entry,
                active: marker::PhantomData,
            },
            driver: self.driver,
        }
    }
}