projects
/
ldk-sample
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
cdca4ee
)
Small improvements of `hex_utils`
author
Elias Rohrer
<ero@tnull.de>
Wed, 14 Sep 2022 10:52:19 +0000
(12:52 +0200)
committer
Elias Rohrer
<ero@tnull.de>
Thu, 15 Sep 2022 07:25:44 +0000
(09:25 +0200)
src/hex_utils.rs
patch
|
blob
|
history
diff --git
a/src/hex_utils.rs
b/src/hex_utils.rs
index 6077a60c52fe5b19b61c4492ce1d07af4cd77e8c..8b853dbb6330826132096a7c2c55f204592be486 100644
(file)
--- a/
src/hex_utils.rs
+++ b/
src/hex_utils.rs
@@
-1,4
+1,5
@@
use bitcoin::secp256k1::PublicKey;
use bitcoin::secp256k1::PublicKey;
+use std::fmt::Write;
pub fn to_vec(hex: &str) -> Option<Vec<u8>> {
let mut out = Vec::with_capacity(hex.len() / 2);
pub fn to_vec(hex: &str) -> Option<Vec<u8>> {
let mut out = Vec::with_capacity(hex.len() / 2);
@@
-23,9
+24,9
@@
pub fn to_vec(hex: &str) -> Option<Vec<u8>> {
#[inline]
pub fn hex_str(value: &[u8]) -> String {
#[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 {
for v in value {
-
res += &format!("{:02x}", v
);
+
write!(&mut res, "{:02x}", v).expect("Unable to write"
);
}
res
}
}
res
}