unwrap_or_exit can now display the error message, requires it to use the Debug trait
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user