From 4dc026bb587c015519150bd9644f2dd2cdf4ede1 Mon Sep 17 00:00:00 2001 From: rascul Date: Fri, 15 Mar 2024 20:53:21 -0500 Subject: [PATCH] add support for serde_json::Error behind feature flag --- Cargo.toml | 6 ++++-- src/lib.rs | 11 +++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 984b32c..ecccffe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,8 @@ description = "Error wrapper that with a message" license = "MIT" keywords = ["error", "result"] -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] +serde_json = { version = "1.0", optional = true } + +[features] +default = [] diff --git a/src/lib.rs b/src/lib.rs index 064e8ec..9f19e95 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -56,3 +56,14 @@ impl From> for Rear { } } } + +#[cfg(feature = "serde_json")] +impl From for Rear { + fn from(error: serde_json::Error) -> Self { + let message: String = error.to_string(); + Self { + error: error.into(), + message: message, + } + } +}