dope-core 0.77.0

Owned native I/O and completion driver for dope
Documentation
use dope_sys::io::reactor::event::kind;
use o3::mem::{Lease, Return, lease::Open};

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

type Completion<'d> =
    storage::Complete<'d, flight::Target, { flight::INDEX_BITS }, { flight::GENERATION_BITS }>;

pub struct Owned<'d> {
    pub(crate) completion: Lease<Completion<'d>, Open>,
    pub(crate) result: Result<Len, Errno>,
    pub(crate) driver: driver::Invariant<'d>,
}

impl Return for Completion<'_> {
    type Item = ();

    fn return_item(self, (): ()) {
        self.finish();
    }
}

impl<'d> Owned<'d> {
    pub(crate) fn new(
        done: Completion<'d>,
        driver: driver::Invariant<'d>,
        result: Result<Len, Errno>,
    ) -> Self {
        done.terminal();
        Self {
            completion: Lease::open(done, ()),
            result,
            driver,
        }
    }

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

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