replace failure with thiserror, fix error not implementing Error
This commit is contained in:
+2
-3
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "json_dotpath"
|
||||
version = "1.0.2"
|
||||
version = "1.0.3"
|
||||
authors = ["Ondřej Hruška <ondra@ondrovo.com>"]
|
||||
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"
|
||||
|
||||
@@ -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<Option<T>>` instead of panicking internally on error.
|
||||
|
||||
+7
-14
@@ -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<serde_json::Error> 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};
|
||||
|
||||
Reference in New Issue
Block a user