dope-core 0.77.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 datagram probe has exactly two receive slots.
unsafe impl memory::raw::Canary for Receive {
    const LAYOUT: Self = Self(settings::Receive::fixed::<
        2,
        { settings::Receive::MIN_DATAGRAM_SLOT.into_nonzero().get() },
    >());
}