From 5213dd156ebb9347744070a7c654456517515ffc Mon Sep 17 00:00:00 2001 From: Sebastian Moser Date: Fri, 14 Jun 2024 17:44:15 +0200 Subject: [PATCH] better Display for MizeError + removed some dead code --- src/core/error.rs | 32 +++++++------------------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/src/core/error.rs b/src/core/error.rs index f0aff00..1a8eb79 100644 --- a/src/core/error.rs +++ b/src/core/error.rs @@ -196,9 +196,13 @@ impl From for MizeError { } */ -impl From for MizeError where E: std::fmt::Display { - fn from(e: E) -> MizeError { - MizeError::new().msg(format!("From generic Rust error: {}", e)) +impl From for MizeError { + #[track_caller] + fn from(value: T) -> Self { + let caller_location = std::panic::Location::caller(); + MizeError::new() + .msg(format!("From {}: {}", std::any::type_name_of_val(&value), value)) + .location(caller_location.into()) } } @@ -239,28 +243,6 @@ impl IntoMizeResult for Result where E: std::fmt::Display { } } -/* -impl IntoMizeResult for io::Result { - #[track_caller] - fn mize_result(self) -> MizeResult { - let caller_location = std::panic::Location::caller(); - - match self { - Ok(val) => MizeResult::Ok(val), - Err(io_err) => MizeResult::Err(MizeError::new().category("io").msg(format!("From an io::Error: {}", io_err))), - } - } - #[track_caller] - fn mize_result_msg(self, msg: dyn Into<&str>) -> MizeResult { - let caller_location = std::panic::Location::caller(); - match self { - Ok(val) => MizeResult::Ok(val), - Err(io_err) => MizeResult::Err(MizeError::new().category("io").msg(msg).msg(format!("From an io::Error: {}", io_err))), - } - } -} -*/ - fn get_error_by_code(code: u32, caller_location: &std::panic::Location) -> MizeError { let err = MizeError {