dope-core 0.76.0

Owned native I/O and completion driver for dope
Documentation
use std::{mem, num};

use crate::driver::{settings, settings::errors};

/// Proven capacity of the shared descriptor and dynamic-ready arena.
#[derive(Clone, Copy, PartialEq, Eq)]
#[repr(transparent)]
pub(crate) struct Ready(num::NonZero<u32>);

const _: () = {
    assert!(mem::size_of::<Ready>() == mem::size_of::<u32>());
    assert!(mem::align_of::<Ready>() == mem::align_of::<u32>());
};

impl Ready {
    pub(crate) const fn raw(self) -> u32 {
        self.0.get()
    }
}

/// Cross-field validated driver construction plan.
#[derive(Clone, Copy, PartialEq, Eq)]
pub(crate) struct Plan<'a> {
    config: &'a settings::Config,
    ready: Ready,
}

impl<'a> Plan<'a> {
    /// Validates cross-field relationships before any driver allocation or I/O.
    pub(in crate::driver) const fn try_new(
        config: &'a settings::Config,
    ) -> Result<Self, errors::Config> {
        let files = config.file_slots().table.nonzero();
        let ready = config.schedule().ready().raw();
        match files.checked_add(ready) {
            Some(capacity) => Ok(Self {
                config,
                ready: Ready(capacity),
            }),
            None => Err(errors::Config::ReadyCapacity {
                files: files.get(),
                ready,
                maximum: u32::MAX,
            }),
        }
    }

    pub(crate) const fn config(&self) -> &'a settings::Config {
        self.config
    }

    pub(crate) const fn ready(self) -> Ready {
        self.ready
    }
}