rust-bitcoin-unsafe-fast/internals
Andrew Poelstra d06bb226bf
Merge rust-bitcoin/rust-bitcoin#1476: Use hex from internals rather than hashes
3e520f9094 Use hex from internals rather than hashes (Martin Habovstiak)

Pull request description:

  `bitcoin-internals` contains a more performant implementation of hex encoding than what `bitcoin_hashes` uses internally. This switches the implementations for formatting trait implementations as a step towards moving over completely.

  The public macros are also changed to delegate to inner type which is technically a breaking change but we will break the API anyway and the consuers should only call the macro on the actual hash newtypes where the inner types already have the appropriate implementations.

  Apart from removing reliance on internal hex from public API this reduces duplicated code generated and compiled. E.g. if you created 10 hash newtypes of SHA256 the formatting implementation would be instantiated 11 times despite being the same.

  To do all this some other changes were required to the hex infrastructure. Mainly modifying `put_bytes` to accept iterator (so that `iter().rev()` can be used) and adding a new `DisplayArray` type. The iterator idea was invented by Tobin C. Harding, this commit just adds a bound check and generalizes over `u8` and `&u8` returning iterators.

  While it may seem that `DisplayByteSlice` would suffice it'd create and initialize a large array even for small arrays wasting performance. Knowing the exact length `DisplayArray` fixes this.

  Another part of refactoring is changing from returning `impl Display` to return `impl LowerHex + UpperHex`. This makes selecting casing less annoying since the consumer no longer needs to import `Case` without cluttering the API with convenience methods.

ACKs for top commit:
  tcharding:
    ACK 3e520f9094
  apoelstra:
    ACK 3e520f9094

Tree-SHA512: 62988cec17550ed35990386e572c0d32dc7107e1c36b7c9099080747e15167e6d66497fb300178afbd22481c0360a6b7a1228fd09402d4ce5d295a8594c02aa6
2022-12-31 19:17:32 +00:00
..
src Merge rust-bitcoin/rust-bitcoin#1476: Use hex from internals rather than hashes 2022-12-31 19:17:32 +00:00
CHANGELOG.md internals: Add CHANGELOG file 2022-11-08 08:40:44 +11:00
Cargo.toml Implement basic support for fast hex encoding 2022-09-13 22:17:31 +02:00
README.md Introduce bitcoin-internals crate 2022-09-13 08:59:57 +10:00
build.rs Activate `rust_v_1_46` when on high-enough rustc 2022-09-14 08:55:02 +02:00

README.md

Rust Bitcoin Internals

This crate is only meant to be used internally by crates in the rust-bitcoin ecosystem.

This crate will never be stabilized, depend on it at your own risk.