dope-core 0.75.0

Owned native I/O and completion driver for dope
Documentation
use std::{mem::MaybeUninit, ptr};

use o3::mem::slot;

use crate::{
    driver::route::{self, kind},
    io::fd::handles,
};

use super::{Completion, Outcome};

impl<'d> Completion<'d> {
    pub fn consume<'event>(
        mut owner: slot::Occupied<'event, Self>,
    ) -> (
        route::Erased<'d, kind::Socket>,
        Outcome<slot::Occupied<'event, handles::CreatedSlot<'d>>>,
    ) {
        let target = owner.0.target;
        match &mut owner.get_mut().0.value {
            Outcome::Created(made) => {
                let value = ptr::from_mut(made);
                drop(owner.into_uninit());
                // SAFETY: the completion's selected field owns its only destructor.
                // Consuming the enclosing owner transfers that right at the same address.
                let made = unsafe {
                    slot::Vacant::new(&mut *value.cast::<MaybeUninit<handles::CreatedSlot<'d>>>())
                        .assume_init()
                };
                (target, Outcome::Created(made))
            }
            Outcome::Failed(cause) => (target, Outcome::Failed(*cause)),
        }
    }
}