feat(core/result): implement std::error::Error for Error

This commit is contained in:
Paul Makles
2024-06-15 10:50:22 +01:00
parent 962c7d62c7
commit b12e728514

View File

@@ -1,3 +1,5 @@
use std::fmt::Display;
#[cfg(feature = "serde")]
#[macro_use]
extern crate serde;
@@ -28,6 +30,14 @@ pub struct Error {
pub location: String,
}
impl Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?} occurred in {}", self.error_type, self.location)
}
}
impl std::error::Error for Error {}
/// Possible error types
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(tag = "type"))]