unwrap_or_exit can now display the error message, requires it to use the Debug trait

This commit is contained in:
2026-05-17 15:52:18 +01:00
parent dd04399784
commit d4947a4434
+7 -4
View File
@@ -11,15 +11,18 @@ pub trait UnwrapOrExit<T>
fn unwrap_or_exit(self, error_message: &str, error_code: i32) -> T;
}
impl<T, E> UnwrapOrExit<T> for Result<T, E>
impl<T, E: std::fmt::Debug> UnwrapOrExit<T> for Result<T, E>
{
fn unwrap_or_exit(self, error_message: &str, error_code: i32) -> T
{
if let Ok(value) = self { value }
else
match self
{
error!("{error_message}");
Ok(value) => value,
Err(error) =>
{
error!("{error_message}: {error:?}");
exit(error_code);
}
}
}
}