dope-core 0.77.0

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

use crate::{
    Errno,
    driver::{self, result},
    io::fd::handles,
};

pub mod raw;

/// Exact cause of a socket submission rejection.
#[derive(Debug)]
pub enum Cause {
    Submit(result::SubmitError),
    Option(Errno),
}

impl From<reactor::Full> for Cause {
    fn from(full: reactor::Full) -> Self {
        Self::Submit(full.into())
    }
}

impl From<Errno> for Cause {
    fn from(cause: Errno) -> Self {
        Self::Option(cause)
    }
}

#[must_use = "a rejected establishment retains its exact descriptor and cause"]
pub struct Rejection<'d> {
    fd: handles::Descriptor<'d>,
    cause: Cause,
}

impl<'d> From<((handles::Descriptor<'d>, driver::Invariant<'d>), Cause)> for Rejection<'d> {
    fn from(((fd, _), cause): ((handles::Descriptor<'d>, driver::Invariant<'d>), Cause)) -> Self {
        Self { fd, cause }
    }
}

impl<'d> Rejection<'d> {
    pub fn into_parts(self) -> (handles::Descriptor<'d>, Cause) {
        (self.fd, self.cause)
    }
}

const _: () = {
    assert!(mem::size_of::<Rejection<'_>>() == mem::size_of::<(handles::Descriptor<'_>, Cause)>());
    assert!(
        mem::align_of::<Rejection<'_>>() == mem::align_of::<(handles::Descriptor<'_>, Cause)>()
    );
};