What changed, and why it matters
This commit is a purely cosmetic renaming of lifetime parameters in Rust code. It changes labels like 's, 'a, and 'e to consistently use 'e across encoder-related code. There is no functional change, no bug fix, and no security impact.
No action required. This is a non-functional cleanup change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch unifies generic lifetime parameter names for the Encodable trait and its associated Encoder types to use ‘e consistently. The changes are alpha-equivalent: every occurrence of ‘s or ‘a as an encoder lifetime is replaced with ‘e, with corresponding where-clause and impl block adjustments. No logic, bounds, or public API semantics are altered.
Changed components
consensus_encoding/examples/encoder.rsconsensus_encoding/src/encode/encoders.rsconsensus_encoding/src/encode/mod.rsconsensus_encoding/tests/encode.rsconsensus_encoding/tests/iter.rsconsensus_encoding/tests/wrappers.rsdocs/adr/0001_consensus_encoding.mdio/src/lib.rsprimitives/src/script/borrowed.rsprimitives/src/witness.rsInspect captured patch +43 / −43
diff --git a/consensus_encoding/examples/encoder.rs b/consensus_encoding/examples/encoder.rs
index d08c8fce..c2cc3d59 100644
--- a/consensus_encoding/examples/encoder.rs
+++ b/consensus_encoding/examples/encoder.rs
@@ -33,10 +33,10 @@ encoding::encoder_newtype! {
}
impl Encodable for Adt {
- type Encoder<'a>
- = AdtEncoder<'a>
+ type Encoder<'e>
+ = AdtEncoder<'e>
where
- Self: 'a;
+ Self: 'e;
fn encoder(&self) -> Self::Encoder<'_> {
let a = Encoder2::new(
diff --git a/consensus_encoding/src/encode/encoders.rs b/consensus_encoding/src/encode/encoders.rs
index 52a5ff8b..2197a812 100644
--- a/consensus_encoding/src/encode/encoders.rs
+++ b/consensus_encoding/src/encode/encoders.rs
@@ -355,10 +355,10 @@ mod tests {
struct TestBytes<'a>(&'a [u8]);
impl Encodable for TestBytes<'_> {
- type Encoder<'s>
- = BytesEncoder<'s>
+ type Encoder<'e>
+ = BytesEncoder<'e>
where
- Self: 's;
+ Self: 'e;
fn encoder(&self) -> Self::Encoder<'_> { BytesEncoder::without_length_prefix(self.0) }
}
@@ -366,10 +366,10 @@ mod tests {
struct TestArray<const N: usize>([u8; N]);
impl<const N: usize> Encodable for TestArray<N> {
- type Encoder<'s>
+ type Encoder<'e>
= ArrayEncoder<N>
where
- Self: 's;
+ Self: 'e;
fn encoder(&self) -> Self::Encoder<'_> { ArrayEncoder::without_length_prefix(self.0) }
}
diff --git a/consensus_encoding/src/encode/mod.rs b/consensus_encoding/src/encode/mod.rs
index 5dcf21f4..84271b70 100644
--- a/consensus_encoding/src/encode/mod.rs
+++ b/consensus_encoding/src/encode/mod.rs
@@ -15,9 +15,9 @@ pub mod encoders;
pub trait Encodable {
/// The encoder associated with this type. Conceptually, the encoder is like
/// an iterator which yields byte slices.
- type Encoder<'s>: Encoder
+ type Encoder<'e>: Encoder
where
- Self: 's;
+ Self: 'e;
/// Constructs a "default encoder" for the type.
fn encoder(&self) -> Self::Encoder<'_>;
@@ -93,17 +93,17 @@ macro_rules! encoder_newtype_exact{
}
/// Yields bytes from any [`Encodable`] instance.
-pub struct EncodableByteIter<'s, T: Encodable + 's> {
- enc: T::Encoder<'s>,
+pub struct EncodableByteIter<'e, T: Encodable + 'e> {
+ enc: T::Encoder<'e>,
position: usize,
}
-impl<'s, T: Encodable + 's> EncodableByteIter<'s, T> {
+impl<'e, T: Encodable + 'e> EncodableByteIter<'e, T> {
/// Constructs a new byte iterator around a provided encodable.
- pub fn new(encodable: &'s T) -> Self { Self { enc: encodable.encoder(), position: 0 } }
+ pub fn new(encodable: &'e T) -> Self { Self { enc: encodable.encoder(), position: 0 } }
}
-impl<'s, T: Encodable + 's> Iterator for EncodableByteIter<'s, T> {
+impl<'e, T: Encodable + 'e> Iterator for EncodableByteIter<'e, T> {
type Item = u8;
fn next(&mut self) -> Option<Self::Item> {
@@ -119,10 +119,10 @@ impl<'s, T: Encodable + 's> Iterator for EncodableByteIter<'s, T> {
}
}
-impl<'s, T> ExactSizeIterator for EncodableByteIter<'s, T>
+impl<'e, T> ExactSizeIterator for EncodableByteIter<'e, T>
where
- T: Encodable + 's,
- T::Encoder<'s>: ExactSizeEncoder,
+ T: Encodable + 'e,
+ T::Encoder<'e>: ExactSizeEncoder,
{
fn len(&self) -> usize { self.enc.len() - self.position }
}
diff --git a/consensus_encoding/tests/encode.rs b/consensus_encoding/tests/encode.rs
index 973af908..21a37695 100644
--- a/consensus_encoding/tests/encode.rs
+++ b/consensus_encoding/tests/encode.rs
@@ -17,10 +17,10 @@ struct TestData(u32);
#[cfg(feature = "alloc")]
impl Encodable for TestData {
- type Encoder<'s>
+ type Encoder<'e>
= ArrayEncoder<4>
where
- Self: 's;
+ Self: 'e;
fn encoder(&self) -> Self::Encoder<'_> {
ArrayEncoder::without_length_prefix(self.0.to_le_bytes())
@@ -33,10 +33,10 @@ struct EmptyData;
#[cfg(feature = "alloc")]
impl Encodable for EmptyData {
- type Encoder<'s>
+ type Encoder<'e>
= ArrayEncoder<0>
where
- Self: 's;
+ Self: 'e;
fn encoder(&self) -> Self::Encoder<'_> { ArrayEncoder::without_length_prefix([]) }
}
@@ -129,10 +129,10 @@ fn encode_slice_encoder_mixed_empty_and_data() {
struct TestBytes(Vec<u8>);
impl Encodable for TestBytes {
- type Encoder<'s>
- = BytesEncoder<'s>
+ type Encoder<'e>
+ = BytesEncoder<'e>
where
- Self: 's;
+ Self: 'e;
fn encoder(&self) -> Self::Encoder<'_> { BytesEncoder::without_length_prefix(&self.0) }
}
diff --git a/consensus_encoding/tests/iter.rs b/consensus_encoding/tests/iter.rs
index 5c8c114e..5b83cc27 100644
--- a/consensus_encoding/tests/iter.rs
+++ b/consensus_encoding/tests/iter.rs
@@ -4,10 +4,10 @@ use hex::BytesToHexIter;
struct TestArray<const N: usize>([u8; N]);
impl<const N: usize> Encodable for TestArray<N> {
- type Encoder<'s>
+ type Encoder<'e>
= ArrayEncoder<N>
where
- Self: 's;
+ Self: 'e;
fn encoder(&self) -> Self::Encoder<'_> { ArrayEncoder::without_length_prefix(self.0) }
}
@@ -15,10 +15,10 @@ impl<const N: usize> Encodable for TestArray<N> {
struct TestCatArray<const N: usize, const M: usize>([u8; N], [u8; M]);
impl<const N: usize, const M: usize> Encodable for TestCatArray<N, M> {
- type Encoder<'s>
+ type Encoder<'e>
= Encoder2<ArrayEncoder<N>, ArrayEncoder<M>>
where
- Self: 's;
+ Self: 'e;
fn encoder(&self) -> Self::Encoder<'_> {
Encoder2::new(
diff --git a/consensus_encoding/tests/wrappers.rs b/consensus_encoding/tests/wrappers.rs
index 8c08a037..1140aafb 100644
--- a/consensus_encoding/tests/wrappers.rs
+++ b/consensus_encoding/tests/wrappers.rs
@@ -97,10 +97,10 @@ fn slice_encoder() {
}
impl Encodable for Test {
- type Encoder<'a>
- = TestEncoder<'a>
+ type Encoder<'e>
+ = TestEncoder<'e>
where
- Self: 'a;
+ Self: 'e;
fn encoder(&self) -> Self::Encoder<'_> {
TestEncoder::new(Encoder2::new(
diff --git a/docs/adr/0001_consensus_encoding.md b/docs/adr/0001_consensus_encoding.md
index 48bb1553..b857c5d5 100644
--- a/docs/adr/0001_consensus_encoding.md
+++ b/docs/adr/0001_consensus_encoding.md
@@ -77,9 +77,9 @@ Encoding is generally infallible (e.g. encoding to `Vec` never fails). Decoding
```rust
pub trait Encodable {
- type Encoder<'s>: Encoder
+ type Encoder<'e>: Encoder
where
- Self: 's;
+ Self: 'e;
fn encoder(&self) -> Self::Encoder<'_>;
}
diff --git a/io/src/lib.rs b/io/src/lib.rs
index 829738c2..9a2f82c7 100644
--- a/io/src/lib.rs
+++ b/io/src/lib.rs
@@ -763,10 +763,10 @@ mod tests {
struct TestData(u32);
impl encoding::Encodable for TestData {
- type Encoder<'s>
+ type Encoder<'e>
= ArrayEncoder<4>
where
- Self: 's;
+ Self: 'e;
fn encoder(&self) -> Self::Encoder<'_> {
ArrayEncoder::without_length_prefix(self.0.to_le_bytes())
diff --git a/primitives/src/script/borrowed.rs b/primitives/src/script/borrowed.rs
index ce092a14..8afddc6a 100644
--- a/primitives/src/script/borrowed.rs
+++ b/primitives/src/script/borrowed.rs
@@ -159,10 +159,10 @@ encoding::encoder_newtype_exact! {
}
impl<T> Encodable for Script<T> {
- type Encoder<'a>
- = ScriptEncoder<'a>
+ type Encoder<'e>
+ = ScriptEncoder<'e>
where
- Self: 'a;
+ Self: 'e;
fn encoder(&self) -> Self::Encoder<'_> {
ScriptEncoder::new(Encoder2::new(
diff --git a/primitives/src/witness.rs b/primitives/src/witness.rs
index 1af098ff..13385f92 100644
--- a/primitives/src/witness.rs
+++ b/primitives/src/witness.rs
@@ -259,13 +259,13 @@ fn decode_cursor(bytes: &[u8], start_of_indices: usize, index: usize) -> Option<
}
/// The encoder for the [`Witness`] type.
-pub struct WitnessEncoder<'a>(Encoder2<CompactSizeEncoder, BytesEncoder<'a>>);
+pub struct WitnessEncoder<'e>(Encoder2<CompactSizeEncoder, BytesEncoder<'e>>);
impl Encodable for Witness {
- type Encoder<'a>
- = WitnessEncoder<'a>
+ type Encoder<'e>
+ = WitnessEncoder<'e>
where
- Self: 'a;
+ Self: 'e;
fn encoder(&self) -> Self::Encoder<'_> {
let num_elements = CompactSizeEncoder::new(self.len());
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.