dope-uring 0.77.0

Owned io_uring backend for dope
Documentation
use dope_sys::{
    memory,
    probe::{State, Stopped, session},
    table::token,
};

use crate::reactor::ring::{
    Session, Waiting,
    session::{Fault, Stage},
};

type Native<T, L, F> = Waiting<Session<T, L, F>, T>;
type Progress<T, L, F> = State<Session<T, L, F>, Native<T, L, F>>;

/// Pending sessions permit cancellation while retaining their exact native owner.
#[repr(transparent)]
pub struct Pending<T: token::Codec, L: memory::raw::Canary, F>(
    pub(super) Waiting<Session<T, L, F>, T>,
);

impl<T: token::Codec, L: memory::raw::Canary, F> Pending<T, L, F> {
    fn retained<E>(failed: Stopped<Native<T, L, F>, E>) -> Stopped<Self, E> {
        failed.map(Self)
    }

    fn stage(state: Progress<T, L, F>) -> Stage<T, L, F> {
        match state {
            State::Idle(state) => State::Idle(state),
            State::Active(waiting) => State::Active(Self(waiting)),
        }
    }

    pub(super) fn stopped(
        failed: Stopped<Progress<T, L, F>, Fault<T>>,
    ) -> Stopped<Stage<T, L, F>, Fault<T>> {
        failed.map(Self::stage)
    }
}

impl<T: token::Codec, L: memory::raw::Canary, F> session::Pending for Pending<T, L, F> {
    type Session = Session<T, L, F>;

    fn resume(
        stopped: Stopped<Self, Fault<T>>,
        report: impl FnMut(Fault<T>),
    ) -> Result<Self, Stopped<Self, Fault<T>>> {
        use dope_sys::probe::raw::Wait as _;
        Waiting::resume(stopped.map(|pending| pending.0), Session::ring, report)
            .map(Self)
            .map_err(Self::retained)
    }

    fn cancel(self) -> Result<Self::Session, Stopped<Stage<T, L, F>, Fault<T>>> {
        use dope_sys::probe::raw::Wait as _;
        self.0.cancel(Session::ring).map_err(Self::stopped)
    }
}