consensus_encoding: encoder docs which are consensus specific
What changed, and why it matters
This commit only changes documentation comments in a Rust Bitcoin library. It clarifies that certain encoding functions and types are specifically tied to Bitcoin consensus encoding rules. No code behavior was changed, so there is no security impact.
No action required. This is a documentation-only change with no security relevance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit updates doc comments in consensus_encoding/src/encode/encoders.rs and consensus_encoding/src/encode/mod.rs. It renames module descriptions, adds ‘consensus’ qualifiers to encoder types and helper functions, and removes a module-level doc title. The diff contains no functional code changes, no new logic, no bug fixes, and no API modifications.
Changed components
consensus_encoding/src/encode/encoders.rsconsensus_encoding/src/encode/mod.rsInspect captured patch +12 / −15
diff --git a/consensus_encoding/src/encode/encoders.rs b/consensus_encoding/src/encode/encoders.rs
index 23639ccb..4d040c7f 100644
--- a/consensus_encoding/src/encode/encoders.rs
+++ b/consensus_encoding/src/encode/encoders.rs
@@ -1,11 +1,10 @@
// SPDX-License-Identifier: CC0-1.0
-//! Collection of "standard encoders".
+//! Primitive and combinator encoder types.
//!
-//! These encoders should not be used directly. Instead, when implementing the [`super::Encode`]
-//! trait on a type, you should define a newtype around one or more of these encoders, and pass
-//! through the [`Encoder`] implementation to your newtype. This avoids leaking encoding
-//! implementation details to the users of your type.
+//! These encoders should not be used directly. Instead, you should define a newtype around one or
+//! more of these encoders, and pass through the [`Encoder`] implementation to your newtype. This
+//! avoids leaking encoding implementation details to the users of your type.
//!
//! For implementing these newtypes, we provide the [`encoder_newtype`] and
//! [`encoder_newtype_exact`] macros.
@@ -116,7 +115,7 @@ impl<const N: usize> ExactSizeEncoder for ArrayRefEncoder<'_, N> {
fn len(&self) -> usize { self.arr.len() }
}
-/// An encoder for a list of encodable types.
+/// An encoder for a list of consensus encodable types.
pub struct SliceEncoder<'e, T: Encode> {
/// The list of references to the objects we are encoding.
sl: &'e [T],
@@ -191,7 +190,7 @@ impl<T: Encode> Encoder for SliceEncoder<'_, T> {
}
}
-/// An encoder for a list of encodable types, including a length prefix.
+/// An encoder for a list of consensus encodable types, including a length prefix.
pub struct PrefixedSliceEncoder<'e, T: Encode>(Encoder2<CompactSizeEncoder, SliceEncoder<'e, T>>);
impl<'e, T: Encode> PrefixedSliceEncoder<'e, T> {
diff --git a/consensus_encoding/src/encode/mod.rs b/consensus_encoding/src/encode/mod.rs
index c859ce47..5cd84991 100644
--- a/consensus_encoding/src/encode/mod.rs
+++ b/consensus_encoding/src/encode/mod.rs
@@ -1,7 +1,5 @@
// SPDX-License-Identifier: CC0-1.0
-//! Consensus Encoding Traits
-
#[cfg(feature = "alloc")]
#[cfg(feature = "hex")]
use alloc::string::String;
@@ -10,7 +8,7 @@ use alloc::vec::Vec;
pub mod encoders;
-/// A Bitcoin object which can be consensus-encoded.
+/// A Bitcoin object which can be consensus encoded.
///
/// To encode something, use the [`Self::encoder`] method to obtain a [`Self::Encoder`], which will
/// behave like an iterator yielding byte slices.
@@ -50,7 +48,7 @@ pub trait Encode {
fn encoder(&self) -> Self::Encoder<'_>;
}
-/// An encoder for a consensus-encodable object.
+/// A pull based encoder that yields bytes in chunks.
///
/// The consumers of a type implementing this encoder trait should generally use it in a loop like
/// this:
@@ -316,7 +314,7 @@ pub trait ExactSizeEncoder: Encoder {
fn is_empty(&self) -> bool { self.len() == 0 }
}
-/// Encodes an object into a vector.
+/// Encodes a consensus encodable type into a vector.
#[cfg(feature = "alloc")]
pub fn encode_to_vec<T>(object: &T) -> Vec<u8>
where
@@ -342,7 +340,7 @@ where
vec
}
-/// Encodes an object into a hex string.
+/// Encodes a consensus encodable type into a hex string.
#[cfg(feature = "alloc")]
#[cfg(feature = "hex")]
pub fn encode_to_hex<T>(object: &T, case: hex::Case) -> String
@@ -364,7 +362,7 @@ where
hex_iter.flatten().map(char::from).collect()
}
-/// Encodes an object to a standard I/O writer.
+/// Encodes a consensus encodable type to a standard I/O writer.
///
/// # Performance
///
@@ -407,7 +405,7 @@ where
Ok(())
}
-/// Checks that the given `value` encodes to `expected`, panicking if it doesn't.
+/// Checks that a consensus encodable `value` encodes to `expected`, panicking if it doesn't.
///
/// Note that the function does not impose any requirements on chunking - whether the encoded bytes
/// are returned as a few large chunks or they are many smaller chunks makes no difference (other
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.