1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use crate::{DeviceID, Fault, utils::Unwind};

/// Something went wrong with a Device.
#[derive(Debug)]
pub enum Crash<Error> {
    /// We were asked to shut down.
    PowerOff(DeviceID),
    /// The Future we were executing panicked.
    Panic(Unwind),
    /// The Future we were executing returned an Err.
    Error(Error),
    /// A device we depended upon faulted.
    Cascade(DeviceID, Fault),
}

impl<Error> Crash<Error> {

    /// Did the future unwind panic?
    pub fn is_panic(&self) -> bool {
        if let Crash::Panic(_) = self { true } else { false }
    }

    /// Did the future return Err?
    pub fn is_error(&self) -> bool {
        if let Crash::Error(_) = self { true } else { false }
    }

    /// Did a Device we depend on fault?
    pub fn is_cascade(&self) -> bool {
        if let Crash::Cascade(_, _) = self { true } else { false }
    }

}