From c60d2e36482560ecd9e17a483a12fd8e41bc4061 Mon Sep 17 00:00:00 2001 From: Yuki Kishimoto Date: Sat, 14 Dec 2024 10:19:00 +0100 Subject: [PATCH] nostr: use generic for `hex::encode` Partially revert e200fbeb Signed-off-by: Yuki Kishimoto --- crates/nostr/src/key/public_key.rs | 2 +- crates/nostr/src/util/hex.rs | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/nostr/src/key/public_key.rs b/crates/nostr/src/key/public_key.rs index 240f09e18..7cb3e0918 100644 --- a/crates/nostr/src/key/public_key.rs +++ b/crates/nostr/src/key/public_key.rs @@ -92,7 +92,7 @@ impl PublicKey { /// Get public key as `hex` string #[inline] pub fn to_hex(&self) -> String { - hex::encode(&self.to_bytes()) + hex::encode(self.to_bytes()) } /// Get public key as `bytes` diff --git a/crates/nostr/src/util/hex.rs b/crates/nostr/src/util/hex.rs index 0a7ba2298..e9ef7bba9 100644 --- a/crates/nostr/src/util/hex.rs +++ b/crates/nostr/src/util/hex.rs @@ -50,7 +50,11 @@ const fn from_digit(num: u8) -> u8 { /// Hex encode #[inline] -pub fn encode(data: &[u8]) -> String { +pub fn encode(data: T) -> String +where + T: AsRef<[u8]>, +{ + let data: &[u8] = data.as_ref(); let mut hex: String = String::with_capacity(2 * data.len()); for byte in data.iter() { hex.push(from_digit(byte >> 4) as char);