1use std::convert::Infallible;
2
3use dope_core::driver::life::{domain, domain::Rejected};
4
5use crate::executor::{create, drive, session};
6
7#[derive(Debug)]
9pub enum Cause<'a, S> {
10 Runtime(create::Kind<'a>),
11 Storage(&'a S),
12 Close {
13 storage: Option<&'a S>,
14 failure: domain::Unmap,
15 },
16}
17
18impl<'a, S> Cause<'a, S> {
19 pub(super) fn closing<O, T, Q>(state: &'a domain::Closing<'_, Rejected<S, O>, T, Q>) -> Self {
20 Self::Close {
21 storage: state.result().as_ref().err().map(|error| &error.cause),
22 failure: state.failure(),
23 }
24 }
25}
26
27#[derive(Debug)]
29pub enum Failure<'a, I, E = drive::Error> {
30 Run {
31 cause: session::Cause<'a>,
32 output: Option<&'a E>,
33 },
34 Execute(&'a E),
35 Install(&'a I),
36}
37
38#[derive(Debug)]
40pub enum Run<'a, S, I, E = drive::Error> {
41 Runtime(create::Kind<'a>),
42 Storage(&'a S),
43 Failure(Failure<'a, I, E>),
44 Close {
45 result: Result<Result<(), Failure<'a, I, E>>, &'a S>,
46 failure: domain::Unmap,
47 },
48}
49
50#[derive(Debug)]
52pub enum Kind<'a, S, T, F = Infallible> {
53 Runtime(create::Kind<'a>),
54 Storage(&'a S),
55 Run(&'a F),
56 Close {
57 result: Result<T, &'a S>,
58 failure: domain::Unmap,
59 },
60}
61
62impl<'a, S, O, T, Q> From<&'a domain::Error<'_, Rejected<S, O>, T, Q>> for Kind<'a, S, &'a T> {
63 fn from(error: &'a domain::Error<'_, Rejected<S, O>, T, Q>) -> Self {
64 match error {
65 domain::Error::Storage(error) => Self::Storage(&error.cause),
66 domain::Error::Close(state) => Self::closing(state),
67 }
68 }
69}
70
71impl<'a, S, T, F> Kind<'a, S, &'a T, F> {
72 pub(super) fn closing<O, Q>(state: &'a domain::Closing<'_, Rejected<S, O>, T, Q>) -> Self {
73 Self::Close {
74 result: state.result().as_ref().map_err(|error| &error.cause),
75 failure: state.failure(),
76 }
77 }
78}
79
80impl<'a, S, T, F> Kind<'a, S, T, F> {
81 pub fn map<U>(self, map: impl FnOnce(T) -> U) -> Kind<'a, S, U, F> {
82 match self {
83 Self::Runtime(error) => Kind::Runtime(error),
84 Self::Storage(error) => Kind::Storage(error),
85 Self::Run(error) => Kind::Run(error),
86 Self::Close { result, failure } => Kind::Close {
87 result: result.map(map),
88 failure,
89 },
90 }
91 }
92}