dope-core 0.77.0

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

use dope_sys::{
    io::reactor::ready,
    ring::enter,
    table::{change, change::Filter},
};

use crate::driver::{
    result::{
        self, Kernel,
        poll::{Missing, Operation},
    },
    route::indices,
};

/// Lossless, allocation-free reactor polling failure.
#[derive(Clone, Copy, Eq, PartialEq, Debug)]
pub enum Cause {
    Timeout {
        requested: time::Duration,
    },
    Submit {
        cause: result::Kernel,
    },
    Wait {
        cause: result::Kernel,
    },
    Cancel {
        cause: result::Kernel,
    },
    System {
        operation: Operation,
        fault: crate::Errno,
    },
    Revoke {
        descriptor: usize,
        filter: Filter,
        errno: crate::Errno,
    },
    Backing {
        operation: Operation,
        index: indices::SlotIndex,
        filter: Filter,
    },
    Missing {
        operation: Operation,
        cause: Missing,
    },
}

impl<E, C> From<enter::Poll<E, C>> for Cause
where
    Kernel: From<E> + From<C>,
{
    fn from(error: enter::Poll<E, C>) -> Self {
        match error {
            enter::Poll::Timeout { requested: span } => Self::Timeout { requested: span },
            enter::Poll::Submit(cause) => Self::Submit {
                cause: Kernel::from(cause),
            },
            enter::Poll::Wait(cause) => Self::Wait {
                cause: Kernel::from(cause),
            },
            enter::Poll::Cancel(cause) => Self::Cancel {
                cause: Kernel::from(cause),
            },
        }
    }
}

impl From<ready::Cause> for Cause {
    fn from(cause: ready::Cause) -> Self {
        match cause {
            ready::Cause::Timeout(span) => Self::Timeout { requested: span },
            ready::Cause::Wait(errno) => Self::System {
                operation: Operation::Wait,
                fault: errno,
            },
            ready::Cause::Changes(errno) => Self::System {
                operation: Operation::Changes,
                fault: errno,
            },
        }
    }
}

impl From<change::Index<indices::SlotIndex>> for Cause {
    fn from(error: change::Index<indices::SlotIndex>) -> Self {
        let (index, filter) = error.into_parts();
        Self::Backing {
            operation: Operation::Changes,
            index,
            filter,
        }
    }
}

impl ready::Failure for Cause {
    type Index = indices::SlotIndex;
    type Missing = Missing;
    type Operation = Operation;

    fn revoke(fd: usize, filter: Filter, errno: dope_sys::Errno) -> Self {
        Self::Revoke {
            descriptor: fd,
            filter,
            errno,
        }
    }

    fn missing(op: Operation, cause: Missing) -> Self {
        Self::Missing {
            operation: op,
            cause,
        }
    }

    fn system(op: Operation, errno: dope_sys::Errno) -> Self {
        Self::System {
            operation: op,
            fault: errno,
        }
    }
}

const _: () = {
    assert!(mem::size_of::<Cause>() == 3 * mem::size_of::<usize>());
    assert!(mem::size_of::<Result<(), Cause>>() == mem::size_of::<Cause>());
};