Skip to content

Commit

Permalink
feat: implement serialize for report
Browse files Browse the repository at this point in the history
  • Loading branch information
thewh1teagle committed Apr 23, 2024
1 parent 7a5c32a commit bc4b529
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions eyre/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ default = ["anyhow", "auto-install", "track-caller"]
anyhow = []
auto-install = []
track-caller = []
serialize = ["dep:serde"]

[dependencies]
indenter = { workspace = true }
once_cell = { workspace = true }
pyo3 = { version = "0.20", optional = true, default-features = false }
serde = { version = "1.0.198", optional = true }

[dev-dependencies]
futures = { version = "0.3", default-features = false }
Expand Down
3 changes: 3 additions & 0 deletions eyre/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -909,5 +909,8 @@ impl AsRef<dyn StdError> for Report {
}
}

#[cfg(feature = "serialize")]
mod serialize;

#[cfg(feature = "pyo3")]
mod pyo3_compat;
11 changes: 11 additions & 0 deletions eyre/src/error/serialize.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use crate::Report;
use serde::{ser::Serializer, Serialize};

impl Serialize for Report {
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str(self.to_string().as_ref())
}
}

0 comments on commit bc4b529

Please sign in to comment.