Skip to content

Commit

Permalink
Convert JSON error to eyre early
Browse files Browse the repository at this point in the history
  • Loading branch information
RReverser committed Sep 16, 2024
1 parent d30b1c4 commit 584a56c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/client/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ use serde::de::DeserializeOwned;
use serde::{Deserialize, Deserializer};

trait FromJsonBytes: Sized {
fn from_json_bytes(bytes: &[u8]) -> serde_json::Result<Self>;
fn from_json_bytes(bytes: &[u8]) -> eyre::Result<Self>;
}

impl<T: DeserializeOwned> FromJsonBytes for T {
fn from_json_bytes(bytes: &[u8]) -> serde_json::Result<Self> {
serde_json::from_slice(bytes)
fn from_json_bytes(bytes: &[u8]) -> eyre::Result<Self> {
Ok(serde_json::from_slice(bytes)?)
}
}

#[derive(Debug)]
struct Flattened<A, B>(pub(crate) A, pub(crate) B);

impl<A: FromJsonBytes, B: FromJsonBytes> FromJsonBytes for Flattened<A, B> {
fn from_json_bytes(bytes: &[u8]) -> serde_json::Result<Self> {
fn from_json_bytes(bytes: &[u8]) -> eyre::Result<Self> {
Ok(Self(A::from_json_bytes(bytes)?, B::from_json_bytes(bytes)?))
}
}
Expand Down

0 comments on commit 584a56c

Please sign in to comment.