consensus_encoding: expose vis fragment on exposed macros
What changed, and why it matters
This commit is a routine API ergonomics improvement. It changes two Rust macros so that the caller can specify the visibility of the generated struct and its constructor (e.g., public, private, or crate-visible), instead of always forcing public visibility. The change is explicitly described as backwards compatible and follows a documented Rust API convention.
No security action required. This is a benign API-quality change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch modifies the encoder_newtype! and encoder_newtype_exact! macros in consensus_encoding/src/encode/mod.rs. It replaces hardcoded pub visibility with a $vis:vis macro fragment, allowing callers to supply their own visibility modifier. The generated struct, its new function, and the recursive invocation in encoder_newtype_exact! all use the caller-provided visibility. This is a purely additive, backwards-compatible macro API change.
Changed components
consensus_encoding/src/encode/mod.rsInspect captured patch +5 / −5
diff --git a/consensus_encoding/src/encode/mod.rs b/consensus_encoding/src/encode/mod.rs
index 84271b70..3e403037 100644
--- a/consensus_encoding/src/encode/mod.rs
+++ b/consensus_encoding/src/encode/mod.rs
@@ -49,14 +49,14 @@ pub trait Encoder {
macro_rules! encoder_newtype{
(
$(#[$($struct_attr:tt)*])*
- pub struct $name:ident<$lt:lifetime>($encoder:ty);
+ $vis:vis struct $name:ident<$lt:lifetime>($encoder:ty);
) => {
$(#[$($struct_attr)*])*
- pub struct $name<$lt>($encoder, core::marker::PhantomData<&$lt $encoder>);
+ $vis struct $name<$lt>($encoder, core::marker::PhantomData<&$lt $encoder>);
impl<$lt> $name<$lt> {
/// Construct a new instance of the newtype encoder
- pub fn new(encoder: $encoder) -> $name<$lt> {
+ $vis fn new(encoder: $encoder) -> $name<$lt> {
$name(encoder, core::marker::PhantomData)
}
}
@@ -78,11 +78,11 @@ macro_rules! encoder_newtype{
macro_rules! encoder_newtype_exact{
(
$(#[$($struct_attr:tt)*])*
- pub struct $name:ident<$lt:lifetime>($encoder:ty);
+ $vis:vis struct $name:ident<$lt:lifetime>($encoder:ty);
) => {
$crate::encoder_newtype! {
$(#[$($struct_attr)*])*
- pub struct $name<$lt>($encoder);
+ $vis struct $name<$lt>($encoder);
}
impl<$lt> $crate::ExactSizeEncoder for $name<$lt> {
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.