Skip to content

Commit 852631a

Browse files
committed
nostr: better Debug trait impl for EventId, PublicKey and Tag
Signed-off-by: Yuki Kishimoto <yukikishimoto@protonmail.com>
1 parent 6ffebcb commit 852631a

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
* nostr: add NIP-50 support to `Filter::match_event` method ([Yuki Kishimoto])
3737
* nostr: remove `Arc<T>` from `OnceCell<T>` in `Event` and `Tag` ([Yuki Kishimoto])
3838
* nostr: move `sig` field from `PartialEvent` to `MissingPartialEvent` ([Yuki Kishimoto])
39+
* nostr: better `Debug` trait impl for `EventId`, `PublicKey` and `Tag` ([Yuki Kishimoto])
3940
* pool: take mutex ownership instead of clone in `InternalRelayPool::get_events_from` ([Yuki Kishimoto])
4041
* pool: remove IDs collection from `InternalRelayPool::get_events_from` ([Yuki Kishimoto])
4142
* pool: better checks before perform queries or send messages to relays ([Yuki Kishimoto])

crates/nostr/src/event/id.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,15 @@ impl From<hex::Error> for Error {
5252
/// 32-bytes lowercase hex-encoded sha256 of the serialized event data
5353
///
5454
/// <https://github.com/nostr-protocol/nips/blob/master/01.md>
55-
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
55+
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
5656
pub struct EventId([u8; 32]);
5757

58+
impl fmt::Debug for EventId {
59+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
60+
write!(f, "EventId({})", self.to_hex())
61+
}
62+
}
63+
5864
impl EventId {
5965
/// Event ID len
6066
pub const LEN: usize = 32;

crates/nostr/src/event/tag/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use alloc::string::{String, ToString};
88
use alloc::vec::Vec;
99
use core::cmp::Ordering;
10+
use core::fmt;
1011
use core::hash::{Hash, Hasher};
1112

1213
#[cfg(feature = "std")]
@@ -33,12 +34,18 @@ use crate::types::url::Url;
3334
use crate::{ImageDimensions, PublicKey, SingleLetterTag, Timestamp, UncheckedUrl};
3435

3536
/// Tag
36-
#[derive(Debug, Clone)]
37+
#[derive(Clone)]
3738
pub struct Tag {
3839
buf: Vec<String>,
3940
standardized: OnceCell<Option<TagStandard>>,
4041
}
4142

43+
impl fmt::Debug for Tag {
44+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
45+
f.debug_tuple("Tag").field(&self.buf).finish()
46+
}
47+
}
48+
4249
impl PartialEq for Tag {
4350
fn eq(&self, other: &Self) -> bool {
4451
self.buf == other.buf

crates/nostr/src/key/public_key.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl From<XOnlyPublicKey> for PublicKey {
3838

3939
impl fmt::Debug for PublicKey {
4040
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
41-
f.debug_tuple("PublicKey").field(&self.to_bytes()).finish()
41+
write!(f, "PublicKey({})", self.to_hex())
4242
}
4343
}
4444

0 commit comments

Comments
 (0)