Skip to main content

dope_sys/engine/
shutdown.rs

1use std::convert::Infallible;
2
3use crate::{
4    engine::Buffer,
5    io::{self, Retry},
6    memory,
7    ring::map,
8};
9
10/// Ends the native reactor and its receive projection as one lifetime.
11pub trait Shutdown: Buffer + Sized {
12    type State: Cleanup;
13
14    fn try_shutdown(self, context: Self::Context) -> Result<(), Self::State>;
15}
16
17/// Retains every resource needed to retry the exact failed shutdown phase.
18pub trait Cleanup: Retry<Failure: Into<Failure<Self::Error>>> {
19    type Error;
20
21    fn failure(&self) -> Failure<Self::Error>;
22}
23
24/// Exact failure from the reactor or its retained receive storage.
25#[derive(Debug, Eq, PartialEq)]
26pub enum Failure<E> {
27    Backend(map::Storage<E>),
28    Context(memory::Error),
29}
30
31impl<E, B: Into<map::Storage<E>>, S: Into<memory::Error>> From<io::Cleanup<B, S>> for Failure<E> {
32    fn from(value: io::Cleanup<B, S>) -> Self {
33        match value {
34            io::Cleanup::Owner(cause) => Self::Backend(cause.into()),
35            io::Cleanup::Storage(cause) => Self::Context(cause.into()),
36        }
37    }
38}
39
40impl Cleanup for Infallible {
41    type Error = Infallible;
42
43    fn failure(&self) -> Failure<Self::Error> {
44        match *self {}
45    }
46}
47
48impl<E> From<Infallible> for Failure<E> {
49    fn from(value: Infallible) -> Self {
50        match value {}
51    }
52}
53
54/// Exact failure retained beside the native retirement that did not finish.
55#[derive(Clone, Copy, Debug, Eq, PartialEq)]
56pub enum Cause<F, P> {
57    Completion(F),
58    Reactor { cause: P, completion: Option<F> },
59    File(P),
60    Tuning,
61}