What changed, and why it matters
This commit adds a standard Rust trait implementation (Extend) to the Witness type, allowing users to append multiple witness elements at once. It is a routine API completeness change with no security relevance.
No security action needed. Treat as a normal API enhancement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch implements Extend<T> for Witness where T: AsRef<[u8]>, delegating to the existing push method. It also adds a unit test verifying that extending a Witness from a slice produces the same result as collecting via FromIterator. The change is purely additive and follows the Rust API guidelines (C-COLLECT).
Changed components
primitives/src/witness.rsInspect captured patch +13 / −0
diff --git a/primitives/src/witness.rs b/primitives/src/witness.rs
index b13b21f6..532f36f1 100644
--- a/primitives/src/witness.rs
+++ b/primitives/src/witness.rs
@@ -686,6 +686,12 @@ impl<T: AsRef<[u8]>> FromIterator<T> for Witness {
}
}
+impl<T: AsRef<[u8]>> Extend<T> for Witness {
+ fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I) {
+ iter.into_iter().for_each(|elem| self.push(elem));
+ }
+}
+
// Serde keep backward compatibility with old Vec<Vec<u8>> format
#[cfg(feature = "serde")]
impl serde::Serialize for Witness {
@@ -1323,6 +1329,13 @@ mod test {
assert_eq!(witness1.len(), witness2.len());
assert_eq!(witness1.to_vec(), witness2.to_vec());
+ // Test that extend works the same as manually pushing
+ let mut witness2 = Witness::new();
+ witness2.extend(&data);
+ assert_eq!(witness1, witness2);
+ assert_eq!(witness1.len(), witness2.len());
+ assert_eq!(witness1.to_vec(), witness2.to_vec());
+
// Test with collect
let bytes4 = [0u8, 123, 75];
let bytes5 = [2u8, 6, 3, 7, 8];
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.