From d1d483491f5f0181e60778e557fadd99b44b5d30 Mon Sep 17 00:00:00 2001 From: Martin Habovstiak Date: Tue, 4 Mar 2025 12:33:04 +0100 Subject: [PATCH] Make `hex` in `internals` optional The `hex` crate is not always desirable - e.g. when the consumer wants to work with raw data only. We already had this optional in `hashes` but if `hashes` is going to depend on `internals` it would break this property. This change makes `hash` optional, since it's easy: there's just one struct that depends on it. --- bitcoin/Cargo.toml | 2 +- internals/Cargo.toml | 6 +++--- internals/src/serde.rs | 2 ++ primitives/Cargo.toml | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/bitcoin/Cargo.toml b/bitcoin/Cargo.toml index 56629a46c..d792a3a7e 100644 --- a/bitcoin/Cargo.toml +++ b/bitcoin/Cargo.toml @@ -29,7 +29,7 @@ base58 = { package = "base58ck", version = "0.2.0", default-features = false, fe bech32 = { version = "0.11.0", default-features = false, features = ["alloc"] } hashes = { package = "bitcoin_hashes", version = "0.16.0", default-features = false, features = ["alloc", "hex"] } hex = { package = "hex-conservative", version = "0.3.0", default-features = false, features = ["alloc"] } -internals = { package = "bitcoin-internals", version = "0.4.0", features = ["alloc"] } +internals = { package = "bitcoin-internals", version = "0.4.0", features = ["alloc", "hex"] } io = { package = "bitcoin-io", version = "0.2.0", default-features = false, features = ["alloc", "hashes"] } primitives = { package = "bitcoin-primitives", version = "0.101.0", default-features = false, features = ["alloc"] } secp256k1 = { version = "0.30.0", default-features = false, features = ["hashes", "alloc", "rand"] } diff --git a/internals/Cargo.toml b/internals/Cargo.toml index 12a5daa1d..374fe62d7 100644 --- a/internals/Cargo.toml +++ b/internals/Cargo.toml @@ -15,13 +15,13 @@ exclude = ["tests", "contrib"] [features] default = [] -std = ["alloc", "hex/std"] -alloc = ["hex/alloc"] +std = ["alloc", "hex?/std"] +alloc = ["hex?/alloc"] test-serde = ["serde", "serde_json", "bincode"] [dependencies] -hex = { package = "hex-conservative", version = "0.3.0", default-features = false } +hex = { package = "hex-conservative", version = "0.3.0", default-features = false, optional = true } serde = { version = "1.0.103", default-features = false, optional = true } # Don't enable these directly, use `test-serde` feature instead. diff --git a/internals/src/serde.rs b/internals/src/serde.rs index f48bc6346..7c25cfae4 100644 --- a/internals/src/serde.rs +++ b/internals/src/serde.rs @@ -310,9 +310,11 @@ macro_rules! serde_round_trip ( }) ); +#[cfg(feature = "hex")] /// Serializes a byte slice using the `hex` crate. pub struct SerializeBytesAsHex<'a>(pub &'a [u8]); +#[cfg(feature = "hex")] impl serde::Serialize for SerializeBytesAsHex<'_> { fn serialize(&self, serializer: S) -> Result where diff --git a/primitives/Cargo.toml b/primitives/Cargo.toml index afb74fd00..013c71493 100644 --- a/primitives/Cargo.toml +++ b/primitives/Cargo.toml @@ -24,7 +24,7 @@ arbitrary = ["dep:arbitrary", "units/arbitrary"] [dependencies] hashes = { package = "bitcoin_hashes", version = "0.16.0", default-features = false, features = ["hex"] } hex = { package = "hex-conservative", version = "0.3.0", default-features = false } -internals = { package = "bitcoin-internals", version = "0.4.0" } +internals = { package = "bitcoin-internals", version = "0.4.0", features = ["hex"] } units = { package = "bitcoin-units", version = "0.2.0", default-features = false } arbitrary = { version = "1.4", optional = true }