dope-core 0.77.0

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

use crate::Errno;

use crate::executor::{InstallError, drive, session};
use crate::topology::lending;

/// Application output and the failure observed while releasing its session.
#[derive(Debug)]
pub enum Error<T, E = Infallible> {
    Drive(drive::Error),
    Quiesce {
        output: T,
        drive: drive::Error,
        disarm: Option<Errno>,
    },
    Install {
        cause: InstallError<E>,
        disarm: Option<Errno>,
    },
}

impl<T, E> Error<T, E> {
    /// Borrows the application result retained through a later session failure.
    pub fn output(&self) -> Option<&T> {
        match self {
            Self::Quiesce { output, .. } => Some(output),
            Self::Drive(_) | Self::Install { .. } => None,
        }
    }

    /// Borrows the failure without moving or formatting application output.
    pub fn cause(&self) -> session::Cause<'_, E> {
        match self {
            Self::Drive(error) => session::Cause::Drive(error),
            Self::Quiesce { drive, disarm, .. } => session::Cause::Quiesce {
                drive,
                disarm: *disarm,
            },
            Self::Install { cause, disarm } => session::Cause::Install {
                cause,
                disarm: *disarm,
            },
        }
    }
}

impl<T, E> From<drive::Error> for Error<T, E> {
    fn from(error: drive::Error) -> Self {
        Self::Drive(error)
    }
}

impl<T, X> From<lending::Error<Infallible, T, X>> for Error<T, X> {
    fn from(error: lending::Error<Infallible, T, X>) -> Self {
        match error {
            lending::Error::Run(error) => error,
            lending::Error::Build(never) => match never {},
        }
    }
}