dope-uring 0.77.0

Owned io_uring backend for dope
Documentation
use std::num::NonZero;

use dope_sys::ring::layout::{Layout, Region};
use o3::base::num::bounded;

#[derive(Clone, Copy, Debug)]
pub(crate) struct Axis {
    entries: NonZero<u32>,
    mask: u32,
}

impl Axis {
    pub(in crate::reactor::ring) fn round(
        region: Region,
        count: NonZero<u32>,
    ) -> Result<Self, Layout> {
        let entries = count.checked_next_power_of_two().ok_or(Layout::Entries {
            region,
            actual: bounded::raw::U32::clamp(count.get() as usize),
        })?;
        Ok(Self {
            entries,
            mask: entries.get() - 1,
        })
    }

    pub(in crate::reactor::ring) fn check(self, region: Region, actual: u32) -> Result<(), Layout> {
        if actual == self.entries.get() {
            return Ok(());
        }
        Err(Layout::Entries {
            region,
            actual: bounded::raw::U32::clamp(actual as usize),
        })
    }

    pub(crate) const fn entries(self) -> NonZero<u32> {
        self.entries
    }

    pub(crate) const fn mask(self) -> u32 {
        self.mask
    }
}