X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fhex_utils.rs;h=8b853dbb6330826132096a7c2c55f204592be486;hb=88bd0ca9ec1c511b3e3eb36095fbacca7ccc78fc;hp=0eee5af03beaa7938f8fd60a54765a79362d6b6b;hpb=147435bfe69b5ebf0af451795db84b5a25d8b383;p=ldk-sample diff --git a/src/hex_utils.rs b/src/hex_utils.rs index 0eee5af..8b853db 100644 --- a/src/hex_utils.rs +++ b/src/hex_utils.rs @@ -1,4 +1,5 @@ -use bitcoin::secp256k1::key::PublicKey; +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 }