dope-core 0.75.0

Owned native I/O and completion driver for dope
Documentation
use crate::Errno;

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

/// Application output and the failure observed while releasing its session.
#[derive(Debug)]
pub enum Error<'report, T, E = std::convert::Infallible> {
    Drive(drive::Error),
    Quiesce {
        output: T,
        drive: &'report 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)
    }
}