Tweaked error handling functions #8

Merged
zack merged 1 commits from error-handling into master 2024-02-14 17:20:12 +00:00
Showing only changes of commit ffe0efede0 - Show all commits

View File

@ -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),
}
}
}