Skip to content

Commit

Permalink
nostr: use generic for hex::encode
Browse files Browse the repository at this point in the history
Partially revert e200fbe

Signed-off-by: Yuki Kishimoto <[email protected]>
  • Loading branch information
yukibtc committed Dec 14, 2024
1 parent f21ffbd commit c60d2e3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion crates/nostr/src/key/public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
6 changes: 5 additions & 1 deletion crates/nostr/src/util/hex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ const fn from_digit(num: u8) -> u8 {

/// Hex encode
#[inline]
pub fn encode(data: &[u8]) -> String {
pub fn encode<T>(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);
Expand Down

0 comments on commit c60d2e3

Please sign in to comment.