dope-core 0.76.0

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

use dope_sys::memory;

use crate::{driver::settings, io::transfer};

/// Immutable validated receive geometry bound to the native backend.
#[derive(Clone, Copy)]
#[repr(transparent)]
pub struct Receive(pub(crate) settings::Receive);

// SAFETY: Receive construction validates a positive bounded slot length and a
// count in 2..=32768 whose product fits isize. Copies retain both values.
unsafe impl memory::raw::Layout for Receive {
    fn entries(self) -> num::NonZero<u16> {
        self.0.count()
    }

    fn capacity(self) -> num::NonZero<u32> {
        self.0.buffer_len().into_nonzero()
    }
}

// SAFETY: the typed slot limit and raw capacity come from the same Receive value.
unsafe impl memory::raw::Receive for Receive {
    type Extent = transfer::Extent;

    fn limit(self) -> transfer::NonZero {
        self.0.buffer_len()
    }
}

// SAFETY: the fixed two-slot canary has the original datagram capacity;
// its first slot has room for the scalar used before any receive is submitted.
unsafe impl memory::raw::Canary for Receive {
    const LAYOUT: Self = {
        const {
            assert!(
                std::mem::size_of::<i32>()
                    <= settings::Receive::MIN_DATAGRAM_SLOT.into_nonzero().get() as usize
            )
        };
        Self(settings::Receive::fixed::<
            2,
            { settings::Receive::MIN_DATAGRAM_SLOT.into_nonzero().get() },
        >())
    };
}