Merge pull request 'Tweaked error handling functions' (#8) from error-handling into master

Reviewed-on: #8
This commit is contained in:
2024-02-14 17:20:12 +00:00

View File

@ -15,9 +15,11 @@ pub enum CriticalError {
} }
impl CriticalError { impl CriticalError {
//TODO: Switch to using ! as the return type for the FnOnce and the entire function when the ! feature is stabilized //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)) { pub fn emergency_procedure(self, procedure: impl FnOnce(CriticalError)) -> ! {
procedure(self); procedure(self);
//TODO: Remove this panic when we switch to ! return type
panic!()
} }
} }
@ -25,7 +27,7 @@ impl CriticalError {
pub trait CriticalErrResult: Copy { pub trait CriticalErrResult: Copy {
type Value: 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 /// 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. /// 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;
@ -38,11 +40,7 @@ impl<T: Copy> CriticalErrResult for Result<T, CriticalError> {
fn err_emproc(self, procedure: impl FnOnce(CriticalError)) -> Self::Value { fn err_emproc(self, procedure: impl FnOnce(CriticalError)) -> Self::Value {
match self { match self {
Ok(val) => val, Ok(val) => val,
Err(error) => { Err(error) => error.emergency_procedure(procedure),
error.emergency_procedure(procedure);
//TODO: Remove this panic when we switch to ! return type
panic!()
},
} }
} }
} }