Skip to content

Commit

Permalink
nostr: refactor JsonUtil to use try_* methods
Browse files Browse the repository at this point in the history
Direct call `unwrap` on `try_as_json` and `try_as_pretty_json` methods.

Signed-off-by: Yuki Kishimoto <[email protected]>
  • Loading branch information
yukibtc committed Dec 9, 2024
1 parent 3d09f11 commit 636b904
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions crates/nostr/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//! Util
use alloc::string::String;
use core::fmt::Debug;

#[cfg(feature = "std")]
use bitcoin::secp256k1::rand::rngs::OsRng;
Expand Down Expand Up @@ -50,7 +51,7 @@ where
<Self as JsonUtil>::Err: From<serde_json::Error>,
{
/// Error
type Err;
type Err: Debug;

/// Deserialize JSON
#[inline]
Expand All @@ -66,7 +67,7 @@ where
/// This method could panic! Use `try_as_json` for error propagation.
#[inline]
fn as_json(&self) -> String {
serde_json::to_string(self).unwrap()
self.try_as_json().unwrap()
}

/// Serialize as JSON string
Expand All @@ -80,7 +81,7 @@ where
/// This method could panic! Use `try_as_pretty_json` for error propagation.
#[inline]
fn as_pretty_json(&self) -> String {
serde_json::to_string_pretty(self).unwrap()
self.try_as_pretty_json().unwrap()
}

/// Serialize as pretty JSON string
Expand Down

0 comments on commit 636b904

Please sign in to comment.