From bc4b529a0ccec4acb47549fe08c327155eafba0a Mon Sep 17 00:00:00 2001 From: thewh1teagle <61390950+thewh1teagle@users.noreply.github.com> Date: Tue, 23 Apr 2024 03:04:40 +0300 Subject: [PATCH 1/4] feat: implement serialize for report --- eyre/Cargo.toml | 2 ++ eyre/src/error.rs | 3 +++ eyre/src/error/serialize.rs | 11 +++++++++++ 3 files changed, 16 insertions(+) create mode 100644 eyre/src/error/serialize.rs diff --git a/eyre/Cargo.toml b/eyre/Cargo.toml index 1085cbb..1d1d7e0 100644 --- a/eyre/Cargo.toml +++ b/eyre/Cargo.toml @@ -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 } diff --git a/eyre/src/error.rs b/eyre/src/error.rs index d6e3d5d..69ea2b6 100644 --- a/eyre/src/error.rs +++ b/eyre/src/error.rs @@ -909,5 +909,8 @@ impl AsRef for Report { } } +#[cfg(feature = "serialize")] +mod serialize; + #[cfg(feature = "pyo3")] mod pyo3_compat; diff --git a/eyre/src/error/serialize.rs b/eyre/src/error/serialize.rs new file mode 100644 index 0000000..6098ec5 --- /dev/null +++ b/eyre/src/error/serialize.rs @@ -0,0 +1,11 @@ +use crate::Report; +use serde::{ser::Serializer, Serialize}; + +impl Serialize for Report { + fn serialize(&self, serializer: S) -> std::result::Result + where + S: Serializer, + { + serializer.serialize_str(self.to_string().as_ref()) + } +} From 61c32fccb25d3120d10ba65cc1b2345dcab30df6 Mon Sep 17 00:00:00 2001 From: thewh1teagle <61390950+thewh1teagle@users.noreply.github.com> Date: Sat, 4 May 2024 20:59:06 +0300 Subject: [PATCH 2/4] feat: include backtrace in serialize --- eyre/src/error/serialize.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eyre/src/error/serialize.rs b/eyre/src/error/serialize.rs index 6098ec5..422b91e 100644 --- a/eyre/src/error/serialize.rs +++ b/eyre/src/error/serialize.rs @@ -6,6 +6,6 @@ impl Serialize for Report { where S: Serializer, { - serializer.serialize_str(self.to_string().as_ref()) + serializer.serialize_str(format!("{:?}", self).as_ref()) } } From cbfecb7551c054da504517c1b4ba9575960f22b7 Mon Sep 17 00:00:00 2001 From: thewh1teagle <61390950+thewh1teagle@users.noreply.github.com> Date: Fri, 28 Jun 2024 18:04:38 +0300 Subject: [PATCH 3/4] chore: rename serialize feature to serde to align with community conventions --- Cargo.lock | 1 + eyre/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index c98d750..274475b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -190,6 +190,7 @@ dependencies = [ "once_cell", "pyo3", "rustversion", + "serde", "syn", "thiserror", "trybuild", diff --git a/eyre/Cargo.toml b/eyre/Cargo.toml index 6074fe9..e4931eb 100644 --- a/eyre/Cargo.toml +++ b/eyre/Cargo.toml @@ -17,7 +17,7 @@ default = ["anyhow", "auto-install", "track-caller"] anyhow = [] auto-install = [] track-caller = [] -serialize = ["dep:serde"] +serde = ["dep:serde"] [dependencies] indenter = { workspace = true } From e517a9079d1b4ef680ed0ada68ea97e62f1f17f7 Mon Sep 17 00:00:00 2001 From: thewh1teagle <61390950+thewh1teagle@users.noreply.github.com> Date: Fri, 28 Jun 2024 18:15:55 +0300 Subject: [PATCH 4/4] chore: correct serde feature use --- eyre/src/error.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eyre/src/error.rs b/eyre/src/error.rs index 72c6c0c..8a4c678 100644 --- a/eyre/src/error.rs +++ b/eyre/src/error.rs @@ -909,7 +909,7 @@ impl AsRef for Report { } } -#[cfg(feature = "serialize")] +#[cfg(feature = "serde")] mod serialize; #[cfg(feature = "pyo3")]