dope-core 0.77.0

Owned native I/O and completion driver for dope
Documentation
use crate::driver::route::{indices::SlotIndex, table::conn};

/// The first position after a nonempty route segment.
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
#[repr(transparent)]
pub struct Edge(pub(in crate::driver::route) SlotIndex);

impl Edge {
    pub const fn checked_add(self, local: SlotIndex) -> Option<SlotIndex> {
        SlotIndex::from_raw(self.raw() as u64 + local.raw() as u64)
    }

    /// Both raw positions retain 0..=SLOT_MASK; after the lower-bound guard,
    /// 0 <= slot - base <= slot <= SLOT_MASK.
    pub const fn offset(self, slot: SlotIndex) -> Option<SlotIndex> {
        if slot.raw() < self.raw() {
            None
        } else {
            // SAFETY: subtracting the smaller route index preserves the slot bound.
            Some(unsafe { SlotIndex::encode(slot.raw() - self.raw()) })
        }
    }

    pub const fn slot(self) -> SlotIndex {
        self.0
    }

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

impl From<conn::Capacity> for Edge {
    fn from(capacity: conn::Capacity) -> Self {
        // SAFETY: the admitted connection count reserves this following route slot.
        Self(unsafe { SlotIndex::encode(capacity.raw()) })
    }
}