Tweaked error handling functions #8
14
src/error.rs
14
src/error.rs
@ -15,9 +15,11 @@ pub enum CriticalError {
|
||||
}
|
||||
|
||||
impl 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)) {
|
||||
//TODO: Switch to using ! as the return type for the FnOnce when the feature is stabilized
|
||||
pub fn emergency_procedure(self, procedure: impl FnOnce(CriticalError)) -> ! {
|
||||
procedure(self);
|
||||
//TODO: Remove this panic when we switch to ! return type
|
||||
panic!()
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,7 +27,7 @@ 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
|
||||
//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;
|
||||
@ -38,11 +40,7 @@ impl<T: Copy> CriticalErrResult for Result<T, CriticalError> {
|
||||
fn err_emproc(self, procedure: impl FnOnce(CriticalError)) -> Self::Value {
|
||||
match self {
|
||||
Ok(val) => val,
|
||||
Err(error) => {
|
||||
error.emergency_procedure(procedure);
|
||||
//TODO: Remove this panic when we switch to ! return type
|
||||
panic!()
|
||||
},
|
||||
Err(error) => error.emergency_procedure(procedure),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user