consensus_encoding: update docs for the new return emums
What changed, and why it matters
This commit only updates documentation comments in a Rust Bitcoin encoding/decoding library. It rewrites explanations to match a recent API change where methods now return named enum values (like EncoderStatus::Finished) instead of plain true/false booleans. No actual code logic was changed, so there is no security impact.
No action required; this is a non-functional documentation update.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff is a documentation-only change across three files in consensus_encoding. It updates doc comments for Decoder::push_bytes, DecoderStatus, Encoder::advance, ExactSizeEncoder, and the crate-level module docs to reflect that advance() now returns EncoderStatus (HasMore/Finished) and push_bytes returns DecoderStatus (NeedsMore/Ready). No executable code, signatures, or behavior were modified.
Changed components
consensus_encoding/src/decode/mod.rsconsensus_encoding/src/encode/mod.rsconsensus_encoding/src/lib.rsInspect captured patch +28 / −20
diff --git a/consensus_encoding/src/decode/mod.rs b/consensus_encoding/src/decode/mod.rs
index 65b662f3..685273d0 100644
--- a/consensus_encoding/src/decode/mod.rs
+++ b/consensus_encoding/src/decode/mod.rs
@@ -58,16 +58,20 @@ pub trait Decoder: Sized {
/// Pushes bytes into the decoder, consuming as much as possible.
///
- /// The slice reference will be advanced to point to the unconsumed portion. Returns `Ok(DecoderStatus::NeedsMore)`
- /// if more bytes are needed to complete decoding, `Ok(DecoderStatus::Ready)` if the decoder is ready to
- /// finalize with [`Self::end`], or `Err(error)` if parsing failed.
+ /// The slice reference will be advanced to point to the unconsumed portion. Returns
+ /// `Ok(DecoderStatus::NeedsMore)` if more bytes are needed to complete decoding,
+ /// `Ok(DecoderStatus::Ready)` if the decoder is ready to finalize with [`Self::end`], or
+ /// `Err(error)` if parsing failed.
+ ///
+ /// Once the decoder returns `Ok(DecoderStatus::Ready)`, subsequent calls to this method will
+ /// continue to return `Ok(DecoderStatus::Ready)` without consuming additional bytes.
///
/// # Errors
///
/// Returns an error if the provided bytes are invalid or malformed according to the decoder's
/// validation rules. Insufficient data (needing more bytes) is *not* an error for this method,
- /// the decoder will simply consume what it can and return `DecoderStatus::NeedsMore` to indicate more data is
- /// needed.
+ /// the decoder will simply consume what it can and return `DecoderStatus::NeedsMore` to
+ /// indicate more data is needed.
///
/// # Panics
///
@@ -108,7 +112,8 @@ pub trait Decoder: Sized {
pub enum DecoderStatus {
/// The decoder needs more data to complete decoding.
///
- /// Continue pushing byte slices with [`Decoder::push_bytes`] until this status changes to [`Ready`](DecoderStatus::Ready).
+ /// Continue pushing byte slices with [`Decoder::push_bytes`] until this status changes to
+ /// [`Ready`](DecoderStatus::Ready).
NeedsMore,
/// The decoder has accumulated sufficient data and is ready to finalize.
diff --git a/consensus_encoding/src/encode/mod.rs b/consensus_encoding/src/encode/mod.rs
index 044a5111..0fa2e1ca 100644
--- a/consensus_encoding/src/encode/mod.rs
+++ b/consensus_encoding/src/encode/mod.rs
@@ -55,7 +55,7 @@ pub trait Encode {
/// ```no-compile
/// loop {
/// process_current_chunk(encoder.current_chunk());
-/// if !encoder.advance() {
+/// if encoder.advance().is_finished() {
/// break
/// }
/// }
@@ -66,8 +66,9 @@ pub trait Encode {
///
/// It is crucial that the callers use the methods in that order: obtain the slice via
/// `current_chunk`, write it somewhere and, once fully written, try to advance the encoder.
-/// Attempting to call any method after [`advance`](Self::advance) returned `false` or calling
-/// `advance` before fully processing the chunks will lead to unspecified buggy behavior.
+/// Attempting to call any method after [`advance`](Self::advance) returned
+/// `EncoderStatus::Finished` or calling `advance` before fully processing the chunks will lead to
+/// unspecified buggy behavior.
///
/// The callers MUST NOT assume that the encoder returns any particular size of the chunks. The
/// implementors are allowed to change the sizes of the chunks as long as the concatenation of all
@@ -87,15 +88,15 @@ pub trait Encoder {
///
/// # Returns
///
- /// - `true` if the encoder has advanced to a new state and [`Self::current_chunk`] will return new data.
- /// - `false` if the encoder is exhausted and has no more states.
+ /// - `EncoderStatus::HasMore` if the encoder has advanced to a new state and [`Self::current_chunk`] will return new data.
+ /// - `EncoderStatus::Finished` if the encoder is exhausted and has no more states.
///
/// # Important
///
- /// After `false` was returned the encoder is in unspecified state. Calling any of its methods
- /// in such state is a bug (but not UB) unless the specific encoder documents otherwise. While
- /// usually the encoder simply stays in the last possible state this MUST NOT be relied upon by
- /// the callers.
+ /// After `EncoderStatus::Finished` was returned the encoder is in unspecified state. Calling
+ /// any of its methods in such state is a bug (but not UB) unless the specific encoder documents
+ /// otherwise. While usually the encoder simply stays in the last possible state this MUST NOT
+ /// be relied upon by the callers.
fn advance(&mut self) -> EncoderStatus;
}
@@ -305,12 +306,14 @@ where
pub trait ExactSizeEncoder: Encoder {
/// The number of bytes remaining that the encoder will yield.
///
- /// **Important**: returns an unspecified value if [`Encoder::advance`] has returned `false`.
+ /// **Important**: returns an unspecified value if [`Encoder::advance`] has returned
+ /// `EncoderStatus::Finished`.
fn len(&self) -> usize;
/// Returns whether the encoder would yield an empty response.
///
- /// **Important**: returns an unspecified value if [`Encoder::advance`] has returned `false`.
+ /// **Important**: returns an unspecified value if [`Encoder::advance`] has returned
+ /// `EncoderStatus::Finished`.
fn is_empty(&self) -> bool { self.len() == 0 }
}
diff --git a/consensus_encoding/src/lib.rs b/consensus_encoding/src/lib.rs
index 485cb565..2dff465d 100644
--- a/consensus_encoding/src/lib.rs
+++ b/consensus_encoding/src/lib.rs
@@ -19,13 +19,13 @@
//!
//! Types implement [`Encode`] to produce an [`Encoder`], which yields encoded bytes in chunks
//! via [`Encoder::current_chunk`] and [`Encoder::advance`]. The caller drives the process by
-//! pulling chunks until `advance` returns `false`.
+//! pulling chunks until `advance` returns [`EncoderStatus::Finished`].
//!
//! # Decoding
//!
//! Types implement [`Decode`] to produce a [`Decoder`], which consumes bytes via
-//! [`Decoder::push_bytes`] until it signals completion by returning `Ok(false)`. The caller then
-//! calls [`Decoder::end`] to obtain the decoded value.
+//! [`Decoder::push_bytes`] until it signals completion by returning `Ok(DecoderStatus::Ready)`. The
+//! caller then calls [`Decoder::end`] to obtain the decoded value.
//!
//! Unlike encoding, decoding is fallible. Both `push_bytes` and `end` return `Result`. I/O errors
//! are handled by the caller, keeping the codec logic I/O-agnostic.
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.