From ffe0efede009d8ef6b46609f10766293675e071e Mon Sep 17 00:00:00 2001 From: Zachary Sunforge Date: Wed, 14 Feb 2024 09:18:36 -0800 Subject: [PATCH] Tweaked error handling functions --- src/error.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/error.rs b/src/error.rs index 08aae35..a761418 100644 --- a/src/error.rs +++ b/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 CriticalErrResult for Result { 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), } } } -- 2.43.0