Skip to main content

dope_core/executor/drive/
error.rs

1use dope_sys::{engine, io::reactor::event::fault};
2use std::{convert::Infallible, mem};
3
4use crate::{
5    Errno,
6    driver::{life, result::poll, schedule::ready},
7};
8
9use crate::executor::drive::{clock, regress::Regression};
10
11/// Failure while driving one executor application.
12
13#[derive(Debug)]
14pub enum Error {
15    Boot(life::Busy),
16    Capacity(ready::Capacity),
17    Poll(poll::Error),
18    Completion(fault::Dispatch<crate::Fault>),
19    Deadline(clock::Range),
20    ClockMovedBackwards(Regression),
21    TimerDisarm(Errno),
22    Shutdown,
23    QuiescenceTimeout,
24    Timeout,
25}
26
27impl Error {
28    pub(crate) const fn timeout(clock::Elapsed: clock::Elapsed) -> Self {
29        Self::Timeout
30    }
31
32    pub(crate) const fn quiesce(clock::Elapsed: clock::Elapsed) -> Self {
33        Self::QuiescenceTimeout
34    }
35}
36
37impl From<Regression> for Error {
38    fn from(error: Regression) -> Self {
39        Self::ClockMovedBackwards(error)
40    }
41}
42
43impl From<Infallible> for Error {
44    fn from(error: Infallible) -> Self {
45        match error {}
46    }
47}
48
49impl From<life::Busy> for Error {
50    fn from(error: life::Busy) -> Self {
51        Self::Boot(error)
52    }
53}
54
55impl From<ready::Capacity> for Error {
56    fn from(error: ready::Capacity) -> Self {
57        Self::Capacity(error)
58    }
59}
60
61impl From<poll::Error> for Error {
62    fn from(error: poll::Error) -> Self {
63        Self::Poll(error)
64    }
65}
66
67impl From<fault::Dispatch<crate::Fault>> for Error {
68    fn from(failure: fault::Dispatch<crate::Fault>) -> Self {
69        Self::Completion(failure)
70    }
71}
72
73impl<P> From<engine::Failure<P, crate::Fault>> for Error
74where
75    crate::Engine: engine::raw::Poll<Error = P>,
76{
77    fn from(failure: engine::Failure<P, crate::Fault>) -> Self {
78        match failure {
79            engine::Failure::Native(error) => Self::Poll(poll::Error::from_backend(error)),
80            engine::Failure::Completion(fault) => Self::Completion(fault),
81        }
82    }
83}
84
85impl From<clock::Range> for Error {
86    fn from(range: clock::Range) -> Self {
87        Self::Deadline(range)
88    }
89}
90
91const _: () = {
92    assert!(!mem::needs_drop::<Error>());
93    assert!(
94        mem::size_of::<Error>()
95            <= mem::size_of::<fault::Dispatch<crate::Fault>>() + mem::align_of::<Error>()
96    );
97};