Skip to content

Commit e553f51

Browse files
committed
nostr: add Jsonutil::as_pretty_json and JsonUtil::try_as_pretty_json methods
Signed-off-by: Yuki Kishimoto <[email protected]>
1 parent 67ce3a2 commit e553f51

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
* nostr: add missing `payload` arg to `EventBuilder::job_result` ([Yuki Kishimoto])
5656
* nostr: add `ConversationKey::new` ([Yuki Kishimoto])
5757
* nostr: add `Request::multi_pay_invoice` constructor ([Yuki Kishimoto])
58+
* nostr: add `Jsonutil::as_pretty_json` and `JsonUtil::try_as_pretty_json` methods ([Yuki Kishimoto])
5859
* pool: add `RelayPoolNotification::Authenticated` variant ([Yuki Kishimoto])
5960
* sdk: add `Client::gift_wrap_to` and `Client::send_private_msg_to` ([reyamir])
6061
* sdk: add option to autoconnect relay on `Client::add_relay` method call ([Yuki Kishimoto])

crates/nostr/src/util/mod.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,33 @@ where
6060
Ok(serde_json::from_slice(json.as_ref())?)
6161
}
6262

63-
/// Serialize to JSON string
63+
/// Serialize as JSON string
6464
///
6565
/// This method could panic! Use `try_as_json` for error propagation.
6666
#[inline]
6767
fn as_json(&self) -> String {
6868
serde_json::to_string(self).unwrap()
6969
}
7070

71-
/// Serialize to JSON string
71+
/// Serialize as JSON string
7272
#[inline]
7373
fn try_as_json(&self) -> Result<String, Self::Err> {
7474
Ok(serde_json::to_string(self)?)
7575
}
76+
77+
/// Serialize as pretty JSON string
78+
///
79+
/// This method could panic! Use `try_as_pretty_json` for error propagation.
80+
#[inline]
81+
fn as_pretty_json(&self) -> String {
82+
serde_json::to_string_pretty(self).unwrap()
83+
}
84+
85+
/// Serialize as pretty JSON string
86+
#[inline]
87+
fn try_as_pretty_json(&self) -> Result<String, Self::Err> {
88+
Ok(serde_json::to_string(self)?)
89+
}
7690
}
7791

7892
/// Event ID or Coordinate

0 commit comments

Comments
 (0)