diff --git a/Cargo.toml b/Cargo.toml index c848f26..0dee0ea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "json_dotpath" -version = "1.0.2" +version = "1.0.3" authors = ["Ondřej Hruška "] edition = "2018" license = "MIT" @@ -16,5 +16,4 @@ categories = [ serde = "1" serde_derive = "1" serde_json = "1" -failure = "0.1.7" -failure_derive = "0.1.7" +thiserror = "1" diff --git a/README.md b/README.md index 7aae8b1..8211c84 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,10 @@ Access members of nested JSON arrays and objects using "dotted paths". ## Changes +### 1.0.3 + +Replaced `failure` with `thiserror`, implement `std::error::Error` for the error type. + ### 1.0.0 The API changed to return `Result>` instead of panicking internally on error. diff --git a/src/lib.rs b/src/lib.rs index a4ee30d..0f57463 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,41 +2,34 @@ use serde::de::DeserializeOwned; use serde::Serialize; use serde_json::{Map, Value}; use std::mem; +use thiserror::Error; #[cfg(test)] #[macro_use] extern crate serde_derive; -#[macro_use] -extern crate failure; /// Errors from dot_path methods -#[derive(Debug, Fail)] +#[derive(Debug, Error)] pub enum Error { /// Path hit a value in the JSON object that is not array or map /// and could not continue the traversal. /// /// (e.g. `foo.bar` in `{"foo": 123}`) - #[fail(display = "Unexpected value reached while traversing path")] + #[error("Unexpected value reached while traversing path")] BadPathElement, /// Array index out of range - #[fail(display = "Invalid array index: {}", _0)] + #[error("Invalid array index: {0}")] BadIndex(usize), /// Invalid (usually empty) key used in Map or Array. /// If the key is valid but out of bounds, `BadIndex` will be used. - #[fail(display = "Invalid key: {}", _0)] + #[error("Invalid key: {0}")] InvalidKey(String), /// Error serializing or deserializing a value - #[fail(display = "Invalid array or map key")] - SerdeError(#[fail(cause)] serde_json::Error), -} - -impl From for Error { - fn from(e: serde_json::Error) -> Self { - Error::SerdeError(e) - } + #[error("Invalid array or map key")] + SerdeError(#[from] serde_json::Error), } use crate::Error::{BadIndex, BadPathElement, InvalidKey};