rust-bitcoin / bitcoin_hashes

Simple library which implements a few hashes and does nothing else
Creative Commons Zero v1.0 Universal
66 stars 52 forks source link

Introduce HexWriter #156

Closed RCasatta closed 2 years ago

RCasatta commented 2 years ago

This struct create an hex string from a writer, in cases where you have an encodable object this allows skipping the creation of the intermediate Vec<u8>

Useful in rust_bitcoin serialize_hex https://github.com/rust-bitcoin/rust-bitcoin/blob/0e82376bf85137494ff220608e80b9c78c1932b5/src/consensus/encode.rs#L149 but needs https://github.com/rust-bitcoin/rust-bitcoin/pull/1027 so that result string size is known ahead of time

test hex::benches::bench_to_hex                   ... bench:       2,669 ns/iter (+/- 233)
test hex::benches::bench_to_hex_writer            ... bench:       2,034 ns/iter (+/- 167)
apoelstra commented 2 years ago

concept ACK, though CI is failing

tcharding commented 2 years ago

CI fail is because you include test in the cfg feature gating but io is not imported for test. Since I did the change to see if tests pass here it is:

#[cfg(any(test, feature = "std"))]
use std::io;
apoelstra commented 2 years ago

@tcharding are your nits addressed?

tcharding commented 2 years ago

Yep, thanks for checking with me!