Skip to content

Remove unstable hex dep from public API of primitives - #5213

Merged
apoelstra merged 2 commits into
rust-bitcoin:masterfrom
tcharding:push-snnrmosxyktx
Oct 31, 2025
Merged

Remove unstable hex dep from public API of primitives#5213
apoelstra merged 2 commits into
rust-bitcoin:masterfrom
tcharding:push-snnrmosxyktx

Conversation

@tcharding

@tcharding tcharding commented Oct 28, 2025

Copy link
Copy Markdown
Member

Adds a dep on hex v1.0.0 and uses it everywhere required so that hex v0.3.0 does not appear in the public API.

Note in the serde stuff we use the unstable hex crate still even though we are decoding because we need access to the inners of the errors. This is the exact reason we added that functionality to hex and then during the 1.0.0 saga it was not included.

With this applied we can see from grepping the API text files that only the v1.0.0 error types are in the public API.

gg '.*hex.*' | grep -v to_hex
all-features.txt:1157:pub bitcoin_primitives::transaction::ParseOutPointError::Txid(hex_conservative::error::DecodeFixedLengthBytesError)
all-features.txt:1239:pub extern crate bitcoin_primitives::hex
all-features.txt:1798:pub fn bitcoin_primitives::witness::Witness::from_hex<I, T>(iter: I) -> core::result::Result<Self, hex_conservative::error::DecodeVariableLengthBytesError> where I: core::iter::traits::collect::IntoIterator<Item = T>, T: core::convert::AsRef<str>
all-features.txt:1922:pub type bitcoin_primitives::BlockHash::Err = hex_conservative::error::DecodeFixedLengthBytesError
all-features.txt:1923:pub type bitcoin_primitives::Ntxid::Err = hex_conservative::error::DecodeFixedLengthBytesError
all-features.txt:1934:pub type bitcoin_primitives::TxMerkleNode::Err = hex_conservative::error::DecodeFixedLengthBytesError
all-features.txt:1935:pub type bitcoin_primitives::Txid::Err = hex_conservative::error::DecodeFixedLengthBytesError
all-features.txt:1936:pub type bitcoin_primitives::WitnessCommitment::Err = hex_conservative::error::DecodeFixedLengthBytesError
all-features.txt:1937:pub type bitcoin_primitives::WitnessMerkleNode::Err = hex_conservative::error::DecodeFixedLengthBytesError
all-features.txt:1940:pub type bitcoin_primitives::Wtxid::Err = hex_conservative::error::DecodeFixedLengthBytesError
all-features.txt:1965:pub type bitcoin_primitives::script::ScriptHash::Err = hex_conservative::error::DecodeFixedLengthBytesError
all-features.txt:1975:pub type bitcoin_primitives::script::WScriptHash::Err = hex_conservative::error::DecodeFixedLengthBytesError

Fix: #5211

Comment thread primitives/src/lib.rs
extern crate serde;

#[cfg(feature = "hex")]
pub extern crate hex_stable as hex;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a technical reason to use the extern crate syntax over pub use hex_stable as hex;?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's just about how they get categorized in the docs.rs output. (I guess that's sorta a technical reason.)

@apoelstra

Copy link
Copy Markdown
Member

In the OP you meant to link to #4808 which is merged now.

We don't want `hex v0.3.0` to appear in the public API of `primitives
1.0.0`.

Add a dep on `hex v1.0.0` and use it for anything that appears in the
public API.

And it seems we do not need the `serde` feature of `hex-unstable` so
remove it.
@tcharding
tcharding marked this pull request as ready for review October 28, 2025 23:45
@apoelstra

Copy link
Copy Markdown
Member

Nice. Good call naming the old one hex_unstable so we'd see immediately if it showed up in the API files.

@nyonson nyonson left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK b7f7782

@apoelstra apoelstra left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK b7f7782; successfully ran local tests

@apoelstra
apoelstra merged commit a95d9c3 into rust-bitcoin:master Oct 31, 2025
25 checks passed
tcharding added a commit to tcharding/rust-bitcoin that referenced this pull request Feb 20, 2026
When I added the `hex` feature (rust-bitcoin#5213) I forgot to tie it into CI.

Test the feature both with and without `std` enabled.
apoelstra added a commit that referenced this pull request Mar 5, 2026
771ebf2 primitives: Unit test hex feature (Tobin C. Harding)

Pull request description:

  When I added the `hex` feature (#5213) I forgot to tie it into CI.
  
  Test the feature both with and without `std` enabled.


ACKs for top commit:
  apoelstra:
    ACK 771ebf2; successfully ran local tests


Tree-SHA512: 9ada3f1af9282977587aecbde076052205ea19036e615b49262f75cb324370a1f344e9a77c4f85547ac9a5466a63d3f1c4f41344664a52fd75af0d554cd3bd2a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WTF: hex 0.3.0 is in the public API of primitives 1.0.0

3 participants