dope-core 0.75.0

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

use crate::{
    Errno,
    driver::{
        self,
        retained::flight::{self, storage},
        route::{self, kind},
    },
    io::{
        self,
        event::{self, entry::Entry},
        transfer::Len,
    },
};

pub type Completion<'d, S = route::Route> = Entry<'d, kind::Send, Result<Len, Errno>, S>;

pub struct Owned<'d> {
    pub(crate) completion: ManuallyDrop<
        storage::Complete<'d, flight::Target, { flight::INDEX_BITS }, { flight::GENERATION_BITS }>,
    >,
    pub(crate) result: Result<Len, Errno>,
    driver: driver::Invariant<'d>,
}

impl<'d> Owned<'d> {
    pub(crate) fn new(
        completion: storage::Complete<
            'd,
            flight::Target,
            { flight::INDEX_BITS },
            { flight::GENERATION_BITS },
        >,
        driver: driver::Invariant<'d>,
        result: Result<Len, Errno>,
    ) -> Self {
        completion.mark_terminal();
        Self {
            completion: ManuallyDrop::new(completion),
            result,
            driver,
        }
    }

    pub fn token(&self) -> route::Erased<'d, kind::Send> {
        self.completion.value().bind(
            self.driver,
            flight::raw::Echo::from_inner(self.completion.echo()),
        )
    }

    pub const fn outcome(&self) -> Result<Len, Errno> {
        self.result
    }
}

impl<'d, S: route::Selection> From<Completion<'d, S>> for io::Event<'d> {
    fn from(done: Completion<'d, S>) -> Self {
        Self(event::Kind::Send(done.erase_route()))
    }
}