dope-core 0.75.0

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

use crate::{
    driver::{route, route::kind},
    io::{event::entry::Entry, fd::handles, socket},
};

mod raw;

#[derive(Clone, Copy)]
pub enum Failure {
    Create(socket::Create),
    Retired,
}

pub enum Outcome<T> {
    Created(T),
    Failed(Failure),
}

/// A socket-creation completion and its affine driver target.
///
/// Safe code cannot mint completion authority.
///
///
/// Completion authority is consumed exactly once.
///
#[repr(transparent)]
pub struct Completion<'d>(Entry<'d, kind::Socket, Outcome<handles::CreatedSlot<'d>>>);

impl<'d> Completion<'d> {
    pub(in crate::io) const fn new(
        target: route::Erased<'d, kind::Socket>,
        outcome: Outcome<handles::CreatedSlot<'d>>,
    ) -> Self {
        Self(Entry::new(target, outcome))
    }

    pub const fn token(&self) -> route::Erased<'d, kind::Socket> {
        self.0.token()
    }

    /// Reclaims any descriptor authority carried by an unconsumed completion.
    pub fn reclaim(self) {
        drop(self);
    }

    pub fn into_parts(
        self,
    ) -> (
        route::Erased<'d, kind::Socket>,
        Outcome<handles::CreatedSlot<'d>>,
    ) {
        self.0.split()
    }
}

const _: () = {
    assert!(mem::size_of::<Failure>() == mem::size_of::<socket::Create>());
    assert!(mem::align_of::<Failure>() == mem::align_of::<socket::Create>());
    assert!(mem::size_of::<Outcome<handles::CreatedSlot<'_>>>() == 2 * mem::size_of::<usize>());
    assert!(mem::align_of::<Outcome<handles::CreatedSlot<'_>>>() == mem::align_of::<usize>());
};