From: Elias Rohrer Date: Wed, 14 Sep 2022 10:52:19 +0000 (+0200) Subject: Small improvements of `hex_utils` X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=d404222a3b923474eb5a564f27935e31c6f4d659;p=ldk-sample Small improvements of `hex_utils` --- diff --git a/src/hex_utils.rs b/src/hex_utils.rs index 6077a60..8b853db 100644 --- a/src/hex_utils.rs +++ b/src/hex_utils.rs @@ -1,4 +1,5 @@ use bitcoin::secp256k1::PublicKey; +use std::fmt::Write; pub fn to_vec(hex: &str) -> Option> { let mut out = Vec::with_capacity(hex.len() / 2); @@ -23,9 +24,9 @@ pub fn to_vec(hex: &str) -> Option> { #[inline] pub fn hex_str(value: &[u8]) -> String { - let mut res = String::with_capacity(64); + let mut res = String::with_capacity(2 * value.len()); for v in value { - res += &format!("{:02x}", v); + write!(&mut res, "{:02x}", v).expect("Unable to write"); } res }