Big dependency updates (#7)
Co-authored-by: Zachary Sunforge <zachary.sunforge@bfpower.io> Reviewed-on: #7
This commit is contained in:
15
src/error.rs
15
src/error.rs
@ -15,7 +15,8 @@ pub enum CriticalError {
|
||||
}
|
||||
|
||||
impl CriticalError {
|
||||
pub fn emergency_procedure(self, procedure: impl FnOnce(CriticalError) -> !) -> ! {
|
||||
//TODO: Switch to using ! as the return type for the FnOnce and the entire function when the ! feature is stabilized
|
||||
pub fn emergency_procedure(self, procedure: impl FnOnce(CriticalError)) {
|
||||
procedure(self);
|
||||
}
|
||||
}
|
||||
@ -24,18 +25,24 @@ impl CriticalError {
|
||||
pub trait CriticalErrResult: Copy {
|
||||
type Value: Copy;
|
||||
|
||||
//TODO: Switch to using ! as the return type for the FnOnce when the ! feature is stabilized
|
||||
/// Execute emergency procedure in the event of a critical, the emergency procedure cannot
|
||||
/// return. It should usually terminate the program, potentially rebooting the device in some sort of recovery mode.
|
||||
fn err_emproc(self, procedure: impl FnOnce(CriticalError) -> !) -> Self::Value;
|
||||
fn err_emproc(self, procedure: impl FnOnce(CriticalError)) -> Self::Value;
|
||||
}
|
||||
|
||||
impl<T: Copy> CriticalErrResult for Result<T, CriticalError> {
|
||||
type Value = T;
|
||||
|
||||
fn err_emproc(self, procedure: impl FnOnce(CriticalError) -> !) -> Self::Value {
|
||||
//TODO: Switch to using ! as the return type for the FnOnce when the ! feature is stabilized
|
||||
fn err_emproc(self, procedure: impl FnOnce(CriticalError)) -> Self::Value {
|
||||
match self {
|
||||
Ok(val) => val,
|
||||
Err(error) => error.emergency_procedure(procedure),
|
||||
Err(error) => {
|
||||
error.emergency_procedure(procedure);
|
||||
//TODO: Remove this panic when we switch to ! return type
|
||||
panic!()
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user