consensus_encoding: Rename _with decoder functions
What changed, and why it matters
This commit is a simple renaming of internal Rust functions from names ending in '_with' to names ending in '_with_decoder'. It does not change what the code does, only what the functions are called, to avoid confusion with another function that already uses '_with' differently. There is no security issue here.
No security action needed. Treat as a normal non-security refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit renames generic decoder helper functions in the consensus_encoding crate: decode_from_hex_with -> decode_from_hex_with_decoder, decode_from_slice_with -> decode_from_slice_with_decoder, decode_from_slice_unbounded_with -> decode_from_slice_unbounded_with_decoder, and decode_from_read_with -> decode_from_read_with_decoder. It also updates all call sites, re-exports, and documentation. The function signatures, trait bounds, and behavior are unchanged. This is a pure API-consistency refactor.
Changed components
consensus_encoding/src/decode/mod.rsconsensus_encoding/src/lib.rsconsensus_encoding/tests/decode.rsbitcoin/src/crypto/sighash.rsInspect captured patch +18 / −17
diff --git a/bitcoin/src/crypto/sighash.rs b/bitcoin/src/crypto/sighash.rs
index ee063131..784acce9 100644
--- a/bitcoin/src/crypto/sighash.rs
+++ b/bitcoin/src/crypto/sighash.rs
@@ -1639,7 +1639,7 @@ mod tests {
let tx: Transaction = decode_from_slice(&tx_bytes).unwrap();
let prevout_bytes = hex::decode_to_vec(prevout_hex).unwrap();
let prevouts =
- encoding::decode_from_slice_with::<encoding::VecDecoder<TxOut>>(&prevout_bytes)
+ encoding::decode_from_slice_with_decoder::<encoding::VecDecoder<TxOut>>(&prevout_bytes)
.unwrap();
let annex_inner;
let annex = match annex_hex {
diff --git a/consensus_encoding/src/decode/mod.rs b/consensus_encoding/src/decode/mod.rs
index a1776fba..a7d933f2 100644
--- a/consensus_encoding/src/decode/mod.rs
+++ b/consensus_encoding/src/decode/mod.rs
@@ -159,7 +159,7 @@ pub fn decode_from_hex<T: Decode>(
///
/// [`CompactSizeDecoder`]: crate::CompactSizeDecoder
#[cfg(feature = "hex")]
-pub fn decode_from_hex_with<D: Decoder + Default>(
+pub fn decode_from_hex_with_decoder<D: Decoder + Default>(
hex: &str,
) -> Result<D::Output, FromHexError<D::Error>> {
decode_from_hex_internal(hex, D::default())
@@ -244,7 +244,7 @@ pub fn decode_from_slice<T: Decode>(
/// during decode.
///
/// [`CompactSizeDecoder`]: crate::CompactSizeDecoder
-pub fn decode_from_slice_with<D: Decoder + Default>(
+pub fn decode_from_slice_with_decoder<D: Decoder + Default>(
bytes: &[u8],
) -> Result<D::Output, DecodeError<D::Error>> {
decode_from_slice_internal(bytes, D::default())
@@ -290,7 +290,7 @@ where
/// use with decoders which don't have a dedicated [`Decode`] implementer
/// (e.g. [`CompactSizeDecoder`]).
///
-/// Unlike [`decode_from_slice_with`], this function will not error if the slice contains
+/// Unlike [`decode_from_slice_with_decoder`], this function will not error if the slice contains
/// additional bytes that are not required to decode. Furthermore, the byte slice reference provided
/// to this function will be updated based on the consumed data, returning the unconsumed bytes.
///
@@ -300,7 +300,7 @@ where
/// insufficient data.
///
/// [`CompactSizeDecoder`]: crate::CompactSizeDecoder
-pub fn decode_from_slice_unbounded_with<D: Decoder + Default>(
+pub fn decode_from_slice_unbounded_with_decoder<D: Decoder + Default>(
bytes: &mut &[u8],
) -> Result<D::Output, D::Error> {
decode_from_slice_unbounded_internal(bytes, D::default())
@@ -358,7 +358,7 @@ where
///
/// [`CompactSizeDecoder`]: crate::CompactSizeDecoder
#[cfg(feature = "std")]
-pub fn decode_from_read_with<D, R>(reader: R) -> Result<D::Output, ReadError<D::Error>>
+pub fn decode_from_read_with_decoder<D, R>(reader: R) -> Result<D::Output, ReadError<D::Error>>
where
D: Decoder + Default,
R: std::io::BufRead,
diff --git a/consensus_encoding/src/lib.rs b/consensus_encoding/src/lib.rs
index 8981aa0b..1ba90358 100644
--- a/consensus_encoding/src/lib.rs
+++ b/consensus_encoding/src/lib.rs
@@ -45,10 +45,10 @@
//! associated decoder. The following variants instead accept a [`Decoder`] type directly,
//! instantiated with [`Default`], and can be used when the output type does not implement [`Decode`]:
//!
-//! * [`decode_from_read_with`]: Counterpart to [`decode_from_read`].
-//! * [`decode_from_slice_with`]: Counterpart to [`decode_from_slice`].
-//! * [`decode_from_slice_unbounded_with`]: Counterpart to [`decode_from_slice_unbounded`].
-//! * [`decode_from_hex_with`]: Counterpart to [`decode_from_hex`].
+//! * [`decode_from_read_with_decoder`]: Counterpart to [`decode_from_read`].
+//! * [`decode_from_slice_with_decoder`]: Counterpart to [`decode_from_slice`].
+//! * [`decode_from_slice_unbounded_with_decoder`]: Counterpart to [`decode_from_slice_unbounded`].
+//! * [`decode_from_hex_with_decoder`]: Counterpart to [`decode_from_hex`].
//!
//! And on the encoding side we provide:
//!
@@ -63,7 +63,7 @@
//!
//! * `std` - Enables std lib I/O driver functions and `std::error::Error` impls (implies `alloc`).
//! * `alloc` - Enables [`encode_to_vec`], `Vec`-based decoders, and allocation-based helpers.
-//! * `hex` - Enables [`decode_from_hex`], [`decode_from_hex_with`], [`encode_to_hex`] and
+//! * `hex` - Enables [`decode_from_hex`], [`decode_from_hex_with_decoder`], [`encode_to_hex`] and
//! [`drain_to_hex`]. Encoding also requires `alloc`.
#![no_std]
@@ -94,7 +94,7 @@ pub mod serde_as_consensus;
pub use self::compact_size::{CompactSizeDecoder, CompactSizeEncoder, CompactSizeU64Decoder};
#[cfg(feature = "hex")]
#[doc(inline)]
-pub use self::decode::{decode_from_hex, decode_from_hex_with};
+pub use self::decode::{decode_from_hex, decode_from_hex_with_decoder};
#[doc(inline)]
pub use self::decode::decoders::{ArrayDecoder, Decoder2, Decoder3, Decoder4, Decoder6};
#[cfg(feature = "alloc")]
@@ -103,13 +103,14 @@ pub use self::decode::decoders::{ByteVecDecoder, VecDecoder};
#[doc(inline)]
pub use self::decode::{
check_decode, check_decoder, decode_from_slice, decode_from_slice_unbounded,
- decode_from_slice_unbounded_with, decode_from_slice_with, Decode, Decoder, DecoderStatus,
+ decode_from_slice_unbounded_with_decoder, decode_from_slice_with_decoder, Decode, Decoder,
+ DecoderStatus,
};
#[cfg(feature = "std")]
#[doc(inline)]
pub use self::decode::{
decode_from_read, decode_from_read_unbuffered, decode_from_read_unbuffered_with,
- decode_from_read_with,
+ decode_from_read_with_decoder,
};
#[doc(inline)]
pub use self::encode::encoders::{
diff --git a/consensus_encoding/tests/decode.rs b/consensus_encoding/tests/decode.rs
index 11639ea2..3a99a019 100644
--- a/consensus_encoding/tests/decode.rs
+++ b/consensus_encoding/tests/decode.rs
@@ -7,7 +7,7 @@ use std::io::{Cursor, Read};
use bitcoin_consensus_encoding as encoding;
#[cfg(feature = "hex")]
-use bitcoin_consensus_encoding::{decode_from_hex, decode_from_hex_with};
+use bitcoin_consensus_encoding::{decode_from_hex, decode_from_hex_with_decoder};
#[cfg(feature = "alloc")]
use encoding::check_decode;
use encoding::{
@@ -295,9 +295,9 @@ fn decode_from_hex_test() {
assert_eq!(result.unwrap().0, [0x01, 0x02, 0x03, 0x04]);
let result: Result<TestArray, _> = decode_from_hex("DEADBEEF");
assert_eq!(result.unwrap().0, [0xDE, 0xAD, 0xBE, 0xEF]);
- let result = decode_from_hex_with::<TestArrayDecoder>("01020304");
+ let result = decode_from_hex_with_decoder::<TestArrayDecoder>("01020304");
assert_eq!(result.unwrap().0, [0x01, 0x02, 0x03, 0x04]);
- let result = decode_from_hex_with::<TestArrayDecoder>("DEADBEEF");
+ let result = decode_from_hex_with_decoder::<TestArrayDecoder>("DEADBEEF");
assert_eq!(result.unwrap().0, [0xDE, 0xAD, 0xBE, 0xEF]);
}
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.