dope-core 0.75.0

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

use crate::driver::schedule::app::batch;

/// An immutable, nonzero upper bound for one batch.
///
/// # Safety
/// Every call for the same value must return the same bound until it is consumed.
pub unsafe trait Limit {
    fn get(&self) -> NonZero<usize>;
}

// SAFETY: `NonZero<usize>` is immutable and returns its exact value.
unsafe impl Limit for NonZero<usize> {
    fn get(&self) -> NonZero<usize> {
        *self
    }
}

impl<'turn, 'd, T: Limit> batch::Reserved<'turn, 'd, T> {
    /// Settles a producer's output under its original admission.
    /// # Safety
    /// `used` must be the count proved under this exact bound and at most its limit.
    pub unsafe fn take(self, used: usize) -> batch::Reserved<'turn, 'd, ()> {
        let Self { mut quota, limit } = self;
        // SAFETY: this consumed reservation owns the exact immutable limit;
        // no child debits exist and the first item is implicit.
        unsafe { quota.settle(limit.get().get() - used.max(1)) };
        batch::Reserved { quota, limit: () }
    }
}