Skip to main content

dope_sys/engine/ring/
create.rs

1use o3::alloc;
2
3use crate::ring::{create, layout::Layout, map::Map};
4
5/// Exact startup failure and every owner whose cleanup remains incomplete.
6pub enum Failure<S, M, P, C, R> {
7    Allocation(alloc::Error),
8    Setup(S),
9    Layout(Layout),
10    Mapping(Map<M>),
11    Primary(P),
12    Cleanup(C),
13    Release(R),
14}
15
16impl<S, M, P, C, R> From<Result<P, C>> for Failure<S, M, P, C, R> {
17    fn from(result: Result<P, C>) -> Self {
18        match result {
19            Ok(primary) => Self::Primary(primary),
20            Err(cleanup) => Self::Cleanup(cleanup),
21        }
22    }
23}
24
25impl<S, M, P, C, R, A> From<create::Error<S, M, A>> for Failure<S, M, P, C, R>
26where
27    C: From<A>,
28{
29    fn from(error: create::Error<S, M, A>) -> Self {
30        match error {
31            create::Error::Setup(cause) => Self::Setup(cause),
32            create::Error::Layout(layout) => Self::Layout(layout),
33            create::Error::Map(cause) => Self::Mapping(cause),
34            create::Error::Cleanup(state) => Self::Cleanup(C::from(state)),
35        }
36    }
37}