consensus_encoding: Add macro example docs
What changed, and why it matters
This commit only adds documentation examples to two Rust macros. It does not change any executable code, logic, or security behavior. There is no security issue here.
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 diff adds rustdoc /// # Examples sections to the encoder_newtype! and encoder_newtype_exact! macros in consensus_encoding/src/encode/mod.rs. The additions are purely documentation comments and doctest examples; no macro expansion logic, trait implementation, or runtime behavior is modified.
Changed components
consensus_encoding/src/encode/mod.rs documentationInspect captured patch +24 / −0
diff --git a/consensus_encoding/src/encode/mod.rs b/consensus_encoding/src/encode/mod.rs
index dec01aa4..e4c9b315 100644
--- a/consensus_encoding/src/encode/mod.rs
+++ b/consensus_encoding/src/encode/mod.rs
@@ -71,6 +71,18 @@ pub trait Encoder {
///
/// The new type will implement the [`Encoder`] trait by forwarding to the wrapped encoder. If your
/// type has a known size consider using [`crate::encoder_newtype_exact`] instead.
+///
+/// # Examples
+/// ```
+/// use bitcoin_consensus_encoding::{encoder_newtype, BytesEncoder};
+///
+/// encoder_newtype! {
+/// /// The encoder for the [`Foo`] type.
+/// pub struct FooEncoder<'e>(BytesEncoder<'e>);
+/// }
+/// ```
+///
+/// For a full example see `./examples/encoder.rs`.
#[macro_export]
macro_rules! encoder_newtype {
(
@@ -102,6 +114,18 @@ macro_rules! encoder_newtype {
///
/// The new type will implement both the [`Encoder`] and [`ExactSizeEncoder`] traits
/// by forwarding to the wrapped encoder.
+///
+/// # Examples
+/// ```
+/// use bitcoin_consensus_encoding::{encoder_newtype_exact, ArrayEncoder};
+///
+/// encoder_newtype_exact! {
+/// /// The encoder for the [`Bar`] type.
+/// pub struct BarEncoder<'e>(ArrayEncoder<32>);
+/// }
+/// ```
+///
+/// For a full example see `./examples/encoder.rs`.
#[macro_export]
macro_rules! encoder_newtype_exact {
(
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.