Commit Graph

6 Commits

Author SHA1 Message Date
Andrew Poelstra f41ec20ee4
Merge rust-bitcoin/rust-bitcoin#1273: Redesign `hex::BufEncoder` to accept owned arrays
1bf885550e Redesign `hex::BufEncoder` to accept owned arrays (Martin Habovstiak)

Pull request description:

  Not being able to create an owned `BufEncoder` prevented returning it from functions which need to allocate the buffer on stack. Such is the case in WIP serde via consensus serialzation.

  This change refactors `OutBytes` to be unsized, adds an `AsOutBytes` trait and uses that one instead of `Into` to perform the conversion.

  Closes #1270

  This is meant as potentially mergeable demonstration. Interestingly, it was easier than I expected.

ACKs for top commit:
  tcharding:
    Except for the question about the `out_bytes` module, ACK 1bf885550e
  apoelstra:
    ACK 1bf885550e

Tree-SHA512: 39bc48e54ae0e66b988ba5ad6ea7ecbe03e5f4c71792df0f8e2b03aa2e97e2c0fac1cb03e84ecac12ec6f13649554b57e1000710c34c638d17d9bb575d0ac0a1
2022-09-15 13:17:36 +00:00
Martin Habovstiak 1bf885550e Redesign `hex::BufEncoder` to accept owned arrays
Not being able to create an owned `BufEncoder` prevented returning it
from functions which need to allocate the buffer on stack. Such is the
case in WIP serde via consensus serialzation.

This change refactors `OutBytes` to be unsized, adds an `AsOutBytes`
trait and uses that one instead of `Into` to perform the conversion.
2022-09-14 19:41:58 +02:00
Martin Habovstiak 6b96050d1f Document `cfg`
This adds previously-forgotten documentation of items only available on
`alloc` feature.
2022-09-14 09:06:25 +02:00
Martin Habovstiak 6fc4860813 Activate `rust_v_1_46` when on high-enough rustc
This adds a build script that automatically activates the cfg if the
version is sufficient. We don't make API changes here, just improve
debugging by enabling `track_caller`.
2022-09-14 08:55:02 +02:00
Martin Habovstiak 040b14ef1a Implement basic support for fast hex encoding
There's a `hex` module in `bitcoin_hashes` which is a bit out of place
and not very fast - it passes each *digit* through dynamic dispatch not
only adding overhead but also not allowing `String` to make better
allocations.

This change adds basic support for hex encoding using a stack-allocated
buffer which minimizes the overhead of dynamic dispatch. It also
provides a new `DisplayHex` trait designed to replace `ToHex` found in
`bitcoin_hashes`.
2022-09-13 22:17:31 +02:00
Tobin C. Harding 834bbf461f Introduce bitcoin-internals crate
Add a new crate `bitcoin-internals` to be used for internal code needed
by multiple soon-to-be-created crates.

Add the `write_err` macro to `bitcoin-internals`, nothing else.

This patch uses a `path` dependency which means `rust-bitcoin` cannot be
released in its current state, will need to be changed once we release
the `bitcoin-internals` crate on `crates.io`.
2022-09-13 08:59:57 +10:00