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, + } + } +}