Configurable Struct

This commit is contained in:
Michael Mikovsky
2025-12-21 12:04:53 -07:00
parent c7d66c5560
commit 78fda07ab2
11 changed files with 160 additions and 98 deletions
+24
View File
@@ -1,3 +1,7 @@
use std::fmt;
pub type Result<T> = std::result::Result<T, ModuleError>;
///Generic error type for module-related operations.
#[derive(Debug, serde::Serialize, serde::Deserialize)]
pub enum ModuleError {
@@ -30,3 +34,23 @@ impl From<Box<dyn std::error::Error>> for ModuleError {
ModuleError::Error(value.to_string())
}
}
impl std::error::Error for ModuleError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
None
}
fn description(&self) -> &str {
"description() is deprecated; use Display"
}
fn cause(&self) -> Option<&dyn std::error::Error> {
Some(self)
}
}
impl fmt::Display for ModuleError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(format!("{:?}", self).as_str())
}
}