primitives: rename Script{Buf,} to GenericScript{Buf,}
What changed, and why it matters
This commit is a purely internal rename in the rust-bitcoin library. It renames the low-level `Script` and `ScriptBuf` types to `GenericScript` and `GenericScriptBuf`, then adds public type aliases so existing code using the old names continues to work unchanged. It is part of a planned refactoring series and does not change any behavior, logic, or security properties.
No security action required. This is a benign internal refactoring commit with no security relevance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch renames Script to GenericScript and ScriptBuf to GenericScriptBuf inside primitives/src/script/borrowed.rs, owned.rs, and mod.rs. It preserves the old names as public type aliases (pub type Script = GenericScript; pub type ScriptBuf = GenericScriptBuf;) so downstream crates are unaffected. All trait implementations, conversions, documentation references, and test imports are updated to use the new internal names. The commit message explicitly states this is a temporary step to later introduce generics and will be undone once all call sites use more specific types. No functional code changes are present.
Changed components
primitives/src/script/borrowed.rsprimitives/src/script/owned.rsprimitives/src/script/mod.rsInspect captured patch +116 / −106
diff --git a/primitives/src/script/borrowed.rs b/primitives/src/script/borrowed.rs
index cf662aa2..adeb5579 100644
--- a/primitives/src/script/borrowed.rs
+++ b/primitives/src/script/borrowed.rs
@@ -7,7 +7,7 @@ use core::ops::{
#[cfg(feature = "arbitrary")]
use arbitrary::{Arbitrary, Unstructured};
-use super::ScriptBuf;
+use super::GenericScriptBuf;
use crate::prelude::{Box, ToOwned, Vec};
internals::transparent_newtype! {
@@ -15,13 +15,13 @@ internals::transparent_newtype! {
///
/// *[See also the `bitcoin::script` module](super).*
///
- /// `Script` is a script slice, the most primitive script type. It's usually seen in its borrowed
- /// form `&Script`. It is always encoded as a series of bytes representing the opcodes and data
+ /// `GenericScript` is a script slice, the most primitive script type. It's usually seen in its borrowed
+ /// form `&GenericScript`. It is always encoded as a series of bytes representing the opcodes and data
/// pushes.
///
/// # Validity
///
- /// `Script` does not have any validity invariants - it's essentially just a marked slice of
+ /// `GenericScript` does not have any validity invariants - it's essentially just a marked slice of
/// bytes. This is similar to [`Path`](std::path::Path) vs [`OsStr`](std::ffi::OsStr) where they
/// are trivially cast-able to each-other and `Path` doesn't guarantee being a usable FS path but
/// having a newtype still has value because of added methods, readability and basic type checking.
@@ -62,13 +62,13 @@ internals::transparent_newtype! {
/// * [CScript definition](https://github.com/bitcoin/bitcoin/blob/d492dc1cdaabdc52b0766bf4cba4bd73178325d0/src/script/script.h#L410)
///
#[derive(PartialOrd, Ord, PartialEq, Eq, Hash)]
- pub struct Script([u8]);
+ pub struct GenericScript([u8]);
- impl Script {
- /// Treat byte slice as `Script`
+ impl GenericScript {
+ /// Treat byte slice as `GenericScript`
pub const fn from_bytes(bytes: &_) -> &Self;
- /// Treat mutable byte slice as `Script`
+ /// Treat mutable byte slice as `GenericScript`
pub fn from_bytes_mut(bytes: &mut _) -> &mut Self;
pub(crate) fn from_boxed_bytes(bytes: Box<_>) -> Box<Self>;
@@ -77,19 +77,19 @@ internals::transparent_newtype! {
}
}
-impl Default for &Script {
+impl Default for &GenericScript {
#[inline]
- fn default() -> Self { Script::new() }
+ fn default() -> Self { GenericScript::new() }
}
-impl ToOwned for Script {
- type Owned = ScriptBuf;
+impl ToOwned for GenericScript {
+ type Owned = GenericScriptBuf;
#[inline]
- fn to_owned(&self) -> Self::Owned { ScriptBuf::from_bytes(self.to_vec()) }
+ fn to_owned(&self) -> Self::Owned { GenericScriptBuf::from_bytes(self.to_vec()) }
}
-impl Script {
+impl GenericScript {
/// Constructs a new empty script.
#[inline]
pub const fn new() -> &'static Self { Self::from_bytes(&[]) }
@@ -125,17 +125,17 @@ impl Script {
#[inline]
pub const fn is_empty(&self) -> bool { self.as_bytes().is_empty() }
- /// Converts a [`Box<Script>`](Box) into a [`ScriptBuf`] without copying or allocating.
+ /// Converts a [`Box<GenericScript>`](Box) into a [`GenericScriptBuf`] without copying or allocating.
#[must_use]
#[inline]
- pub fn into_script_buf(self: Box<Self>) -> ScriptBuf {
+ pub fn into_script_buf(self: Box<Self>) -> GenericScriptBuf {
let rw = Box::into_raw(self) as *mut [u8];
// SAFETY: copied from `std`
// The pointer was just created from a box without deallocating
// Casting a transparent struct wrapping a slice to the slice pointer is sound (same
// layout).
let inner = unsafe { Box::from_raw(rw) };
- ScriptBuf::from_bytes(Vec::from(inner))
+ GenericScriptBuf::from_bytes(Vec::from(inner))
}
/// Gets the hex representation of this script.
@@ -152,19 +152,19 @@ impl Script {
}
#[cfg(feature = "arbitrary")]
-impl<'a> Arbitrary<'a> for &'a Script {
+impl<'a> Arbitrary<'a> for &'a GenericScript {
#[inline]
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
let v = <&'a [u8]>::arbitrary(u)?;
- Ok(Script::from_bytes(v))
+ Ok(GenericScript::from_bytes(v))
}
}
macro_rules! delegate_index {
($($type:ty),* $(,)?) => {
$(
- /// Script subslicing operation - read [slicing safety](#slicing-safety)!
- impl Index<$type> for Script {
+ /// [`GenericScript`] subslicing operation - read [slicing safety](#slicing-safety)!
+ impl Index<$type> for GenericScript {
type Output = Self;
#[inline]
@@ -189,9 +189,9 @@ delegate_index!(
#[cfg(test)]
mod tests {
#[cfg(feature = "alloc")]
- use alloc::vec;
+ use alloc::{borrow::ToOwned, vec};
- use super::*;
+ use super::super::Script;
#[test]
fn script_from_bytes() {
diff --git a/primitives/src/script/mod.rs b/primitives/src/script/mod.rs
index 233cede0..d985b402 100644
--- a/primitives/src/script/mod.rs
+++ b/primitives/src/script/mod.rs
@@ -25,24 +25,30 @@ use crate::prelude::{Borrow, BorrowMut, Box, Cow, ToOwned, Vec};
#[rustfmt::skip] // Keep public re-exports separate.
#[doc(inline)]
pub use self::{
- borrowed::Script,
- owned::ScriptBuf,
+ borrowed::GenericScript,
+ owned::GenericScriptBuf,
};
+/// Placeholder doc (will be replaced in later commit)
+pub type Script = GenericScript;
+
+/// Placeholder doc (will be replaced in later commit)
+pub type ScriptBuf = GenericScriptBuf;
+
/// The maximum allowed redeem script size for a P2SH output.
pub const MAX_REDEEM_SCRIPT_SIZE: usize = 520;
/// The maximum allowed redeem script size of the witness script.
pub const MAX_WITNESS_SCRIPT_SIZE: usize = 10_000;
hashes::hash_newtype! {
- /// A 160-bit hash of Bitcoin Script bytecode.
+ /// A 160-bit hash of Bitcoin GenericScript bytecode.
///
/// Note: there is another "script hash" object in bitcoin ecosystem (Electrum protocol) that
/// uses 256-bit hash and hashes a semantically different script. Thus, this type cannot
/// represent it.
pub struct ScriptHash(hash160::Hash);
- /// SegWit (256-bit) version of a Bitcoin Script bytecode hash.
+ /// SegWit (256-bit) version of a Bitcoin GenericScript bytecode hash.
///
/// Note: there is another "script hash" object in bitcoin ecosystem (Electrum protocol) that
/// looks similar to this one also being SHA256, however, they hash semantically different
@@ -229,21 +235,21 @@ impl fmt::Display for WitnessScriptSizeError {
#[cfg(feature = "std")]
impl std::error::Error for WitnessScriptSizeError {}
-// We keep all the `Script` and `ScriptBuf` impls together since it's easier to see side-by-side.
+// We keep all the `GenericScript` and `GenericScriptBuf` impls together since it's easier to see side-by-side.
-impl From<ScriptBuf> for Box<Script> {
+impl From<GenericScriptBuf> for Box<GenericScript> {
#[inline]
- fn from(v: ScriptBuf) -> Self { v.into_boxed_script() }
+ fn from(v: GenericScriptBuf) -> Self { v.into_boxed_script() }
}
-impl From<ScriptBuf> for Cow<'_, Script> {
+impl From<GenericScriptBuf> for Cow<'_, GenericScript> {
#[inline]
- fn from(value: ScriptBuf) -> Self { Cow::Owned(value) }
+ fn from(value: GenericScriptBuf) -> Self { Cow::Owned(value) }
}
-impl<'a> From<Cow<'a, Script>> for ScriptBuf {
+impl<'a> From<Cow<'a, GenericScript>> for GenericScriptBuf {
#[inline]
- fn from(value: Cow<'a, Script>) -> Self {
+ fn from(value: Cow<'a, GenericScript>) -> Self {
match value {
Cow::Owned(owned) => owned,
Cow::Borrowed(borrowed) => borrowed.into(),
@@ -251,9 +257,9 @@ impl<'a> From<Cow<'a, Script>> for ScriptBuf {
}
}
-impl<'a> From<Cow<'a, Script>> for Box<Script> {
+impl<'a> From<Cow<'a, GenericScript>> for Box<GenericScript> {
#[inline]
- fn from(value: Cow<'a, Script>) -> Self {
+ fn from(value: Cow<'a, GenericScript>) -> Self {
match value {
Cow::Owned(owned) => owned.into(),
Cow::Borrowed(borrowed) => borrowed.into(),
@@ -261,97 +267,101 @@ impl<'a> From<Cow<'a, Script>> for Box<Script> {
}
}
-impl<'a> From<&'a Script> for Box<Script> {
+impl<'a> From<&'a GenericScript> for Box<GenericScript> {
#[inline]
- fn from(value: &'a Script) -> Self { value.to_owned().into() }
+ fn from(value: &'a GenericScript) -> Self { value.to_owned().into() }
}
-impl<'a> From<&'a Script> for ScriptBuf {
+impl<'a> From<&'a GenericScript> for GenericScriptBuf {
#[inline]
- fn from(value: &'a Script) -> Self { value.to_owned() }
+ fn from(value: &'a GenericScript) -> Self { value.to_owned() }
}
-impl<'a> From<&'a Script> for Cow<'a, Script> {
+impl<'a> From<&'a GenericScript> for Cow<'a, GenericScript> {
#[inline]
- fn from(value: &'a Script) -> Self { Cow::Borrowed(value) }
+ fn from(value: &'a GenericScript) -> Self { Cow::Borrowed(value) }
}
/// Note: This will fail to compile on old Rust for targets that don't support atomics
#[cfg(target_has_atomic = "ptr")]
-impl<'a> From<&'a Script> for Arc<Script> {
+impl<'a> From<&'a GenericScript> for Arc<GenericScript> {
#[inline]
- fn from(value: &'a Script) -> Self { Script::from_arc_bytes(Arc::from(value.as_bytes())) }
+ fn from(value: &'a GenericScript) -> Self {
+ GenericScript::from_arc_bytes(Arc::from(value.as_bytes()))
+ }
}
-impl<'a> From<&'a Script> for Rc<Script> {
+impl<'a> From<&'a GenericScript> for Rc<GenericScript> {
#[inline]
- fn from(value: &'a Script) -> Self { Script::from_rc_bytes(Rc::from(value.as_bytes())) }
+ fn from(value: &'a GenericScript) -> Self {
+ GenericScript::from_rc_bytes(Rc::from(value.as_bytes()))
+ }
}
-impl From<Vec<u8>> for ScriptBuf {
+impl From<Vec<u8>> for GenericScriptBuf {
#[inline]
- fn from(v: Vec<u8>) -> Self { ScriptBuf::from_bytes(v) }
+ fn from(v: Vec<u8>) -> Self { GenericScriptBuf::from_bytes(v) }
}
-impl From<ScriptBuf> for Vec<u8> {
+impl From<GenericScriptBuf> for Vec<u8> {
#[inline]
- fn from(v: ScriptBuf) -> Self { v.into_bytes() }
+ fn from(v: GenericScriptBuf) -> Self { v.into_bytes() }
}
-impl AsRef<Script> for Script {
+impl AsRef<GenericScript> for GenericScript {
#[inline]
fn as_ref(&self) -> &Self { self }
}
-impl AsRef<Script> for ScriptBuf {
+impl AsRef<GenericScript> for GenericScriptBuf {
#[inline]
- fn as_ref(&self) -> &Script { self }
+ fn as_ref(&self) -> &GenericScript { self }
}
-impl AsRef<[u8]> for Script {
+impl AsRef<[u8]> for GenericScript {
#[inline]
fn as_ref(&self) -> &[u8] { self.as_bytes() }
}
-impl AsRef<[u8]> for ScriptBuf {
+impl AsRef<[u8]> for GenericScriptBuf {
#[inline]
fn as_ref(&self) -> &[u8] { self.as_bytes() }
}
-impl AsMut<Script> for Script {
+impl AsMut<GenericScript> for GenericScript {
#[inline]
fn as_mut(&mut self) -> &mut Self { self }
}
-impl AsMut<Script> for ScriptBuf {
+impl AsMut<GenericScript> for GenericScriptBuf {
#[inline]
- fn as_mut(&mut self) -> &mut Script { self }
+ fn as_mut(&mut self) -> &mut GenericScript { self }
}
-impl AsMut<[u8]> for Script {
+impl AsMut<[u8]> for GenericScript {
#[inline]
fn as_mut(&mut self) -> &mut [u8] { self.as_mut_bytes() }
}
-impl AsMut<[u8]> for ScriptBuf {
+impl AsMut<[u8]> for GenericScriptBuf {
#[inline]
fn as_mut(&mut self) -> &mut [u8] { self.as_mut_bytes() }
}
-impl fmt::Debug for Script {
+impl fmt::Debug for GenericScript {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- f.write_str("Script(")?;
+ f.write_str("GenericScript(")?;
fmt::Display::fmt(self, f)?;
f.write_str(")")
}
}
-impl fmt::Debug for ScriptBuf {
+impl fmt::Debug for GenericScriptBuf {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Debug::fmt(self.as_script(), f) }
}
-impl fmt::Display for Script {
+impl fmt::Display for GenericScript {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
// This has to be a macro because it needs to break the loop
macro_rules! read_push_data_len {
@@ -424,13 +434,13 @@ impl fmt::Display for Script {
}
}
-impl fmt::Display for ScriptBuf {
+impl fmt::Display for GenericScriptBuf {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Display::fmt(self.as_script(), f) }
}
#[cfg(feature = "hex")]
-impl fmt::LowerHex for Script {
+impl fmt::LowerHex for GenericScript {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::LowerHex::fmt(&self.as_bytes().as_hex(), f)
@@ -438,13 +448,13 @@ impl fmt::LowerHex for Script {
}
#[cfg(feature = "hex")]
-impl fmt::LowerHex for ScriptBuf {
+impl fmt::LowerHex for GenericScriptBuf {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::LowerHex::fmt(self.as_script(), f) }
}
#[cfg(feature = "hex")]
-impl fmt::UpperHex for Script {
+impl fmt::UpperHex for GenericScript {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::UpperHex::fmt(&self.as_bytes().as_hex(), f)
@@ -452,48 +462,48 @@ impl fmt::UpperHex for Script {
}
#[cfg(feature = "hex")]
-impl fmt::UpperHex for ScriptBuf {
+impl fmt::UpperHex for GenericScriptBuf {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::UpperHex::fmt(self.as_script(), f) }
}
-impl Borrow<Script> for ScriptBuf {
+impl Borrow<GenericScript> for GenericScriptBuf {
#[inline]
- fn borrow(&self) -> &Script { self }
+ fn borrow(&self) -> &GenericScript { self }
}
-impl BorrowMut<Script> for ScriptBuf {
+impl BorrowMut<GenericScript> for GenericScriptBuf {
#[inline]
- fn borrow_mut(&mut self) -> &mut Script { self }
+ fn borrow_mut(&mut self) -> &mut GenericScript { self }
}
-impl PartialEq<ScriptBuf> for Script {
+impl PartialEq<GenericScriptBuf> for GenericScript {
#[inline]
- fn eq(&self, other: &ScriptBuf) -> bool { self.eq(other.as_script()) }
+ fn eq(&self, other: &GenericScriptBuf) -> bool { self.eq(other.as_script()) }
}
-impl PartialEq<Script> for ScriptBuf {
+impl PartialEq<GenericScript> for GenericScriptBuf {
#[inline]
- fn eq(&self, other: &Script) -> bool { self.as_script().eq(other) }
+ fn eq(&self, other: &GenericScript) -> bool { self.as_script().eq(other) }
}
-impl PartialOrd<Script> for ScriptBuf {
+impl PartialOrd<GenericScript> for GenericScriptBuf {
#[inline]
- fn partial_cmp(&self, other: &Script) -> Option<Ordering> {
+ fn partial_cmp(&self, other: &GenericScript) -> Option<Ordering> {
self.as_script().partial_cmp(other)
}
}
-impl PartialOrd<ScriptBuf> for Script {
+impl PartialOrd<GenericScriptBuf> for GenericScript {
#[inline]
- fn partial_cmp(&self, other: &ScriptBuf) -> Option<Ordering> {
+ fn partial_cmp(&self, other: &GenericScriptBuf) -> Option<Ordering> {
self.partial_cmp(other.as_script())
}
}
#[cfg(feature = "serde")]
-impl serde::Serialize for Script {
- /// User-facing serialization for `Script`.
+impl serde::Serialize for GenericScript {
+ /// User-facing serialization for `GenericScript`.
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
@@ -508,14 +518,14 @@ impl serde::Serialize for Script {
/// Can only deserialize borrowed bytes.
#[cfg(feature = "serde")]
-impl<'de> serde::Deserialize<'de> for &'de Script {
+impl<'de> serde::Deserialize<'de> for &'de GenericScript {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
struct Visitor;
impl<'de> serde::de::Visitor<'de> for Visitor {
- type Value = &'de Script;
+ type Value = &'de GenericScript;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str("borrowed bytes")
@@ -525,7 +535,7 @@ impl<'de> serde::Deserialize<'de> for &'de Script {
where
E: serde::de::Error,
{
- Ok(Script::from_bytes(v))
+ Ok(GenericScript::from_bytes(v))
}
}
@@ -533,7 +543,7 @@ impl<'de> serde::Deserialize<'de> for &'de Script {
use crate::serde::de::Error;
return Err(D::Error::custom(
- "deserialization of `&Script` from human-readable formats is not possible",
+ "deserialization of `&GenericScript` from human-readable formats is not possible",
));
}
@@ -542,8 +552,8 @@ impl<'de> serde::Deserialize<'de> for &'de Script {
}
#[cfg(feature = "serde")]
-impl serde::Serialize for ScriptBuf {
- /// User-facing serialization for `Script`.
+impl serde::Serialize for GenericScriptBuf {
+ /// User-facing serialization for `GenericScript`.
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
@@ -553,7 +563,7 @@ impl serde::Serialize for ScriptBuf {
}
#[cfg(feature = "serde")]
-impl<'de> serde::Deserialize<'de> for ScriptBuf {
+impl<'de> serde::Deserialize<'de> for GenericScriptBuf {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
@@ -565,7 +575,7 @@ impl<'de> serde::Deserialize<'de> for ScriptBuf {
if deserializer.is_human_readable() {
struct Visitor;
impl serde::de::Visitor<'_> for Visitor {
- type Value = ScriptBuf;
+ type Value = GenericScriptBuf;
fn expecting(&self, formatter: &mut Formatter) -> fmt::Result {
formatter.write_str("a script hex")
@@ -576,7 +586,7 @@ impl<'de> serde::Deserialize<'de> for ScriptBuf {
E: serde::de::Error,
{
let v = Vec::from_hex(v).map_err(E::custom)?;
- Ok(ScriptBuf::from(v))
+ Ok(GenericScriptBuf::from(v))
}
}
deserializer.deserialize_str(Visitor)
@@ -584,7 +594,7 @@ impl<'de> serde::Deserialize<'de> for ScriptBuf {
struct BytesVisitor;
impl serde::de::Visitor<'_> for BytesVisitor {
- type Value = ScriptBuf;
+ type Value = GenericScriptBuf;
fn expecting(&self, formatter: &mut Formatter) -> fmt::Result {
formatter.write_str("a script Vec<u8>")
@@ -594,14 +604,14 @@ impl<'de> serde::Deserialize<'de> for ScriptBuf {
where
E: serde::de::Error,
{
- Ok(ScriptBuf::from(v.to_vec()))
+ Ok(GenericScriptBuf::from(v.to_vec()))
}
fn visit_byte_buf<E>(self, v: Vec<u8>) -> Result<Self::Value, E>
where
E: serde::de::Error,
{
- Ok(ScriptBuf::from(v))
+ Ok(GenericScriptBuf::from(v))
}
}
deserializer.deserialize_byte_buf(BytesVisitor)
diff --git a/primitives/src/script/owned.rs b/primitives/src/script/owned.rs
index 9fb73fae..4eac2651 100644
--- a/primitives/src/script/owned.rs
+++ b/primitives/src/script/owned.rs
@@ -10,11 +10,11 @@ use crate::prelude::{Box, Vec};
/// An owned, growable script.
///
-/// `ScriptBuf` is the most common script type that has the ownership over the contents of the
+/// `GenericScriptBuf` is the most common script type that has the ownership over the contents of the
/// script. It has a close relationship with its borrowed counterpart, [`Script`].
///
/// Just as other similar types, this implements [`Deref`], so [deref coercions] apply. Also note
-/// that all the safety/validity restrictions that apply to [`Script`] apply to `ScriptBuf` as well.
+/// that all the safety/validity restrictions that apply to [`Script`] apply to `GenericScriptBuf` as well.
///
/// # Hexadecimal strings
///
@@ -27,9 +27,9 @@ use crate::prelude::{Box, Vec};
/// [`examples/script.rs`]: <https://github.com/rust-bitcoin/rust-bitcoin/blob/master/bitcoin/examples/script.rs>
/// [deref coercions]: https://doc.rust-lang.org/std/ops/trait.Deref.html#more-on-deref-coercion
#[derive(Default, Clone, PartialOrd, Ord, PartialEq, Eq, Hash)]
-pub struct ScriptBuf(Vec<u8>);
+pub struct GenericScriptBuf(Vec<u8>);
-impl ScriptBuf {
+impl GenericScriptBuf {
/// Constructs a new empty script.
#[inline]
pub const fn new() -> Self { Self::from_bytes(Vec::new()) }
@@ -59,7 +59,7 @@ impl ScriptBuf {
#[inline]
pub fn into_bytes(self) -> Vec<u8> { self.0 }
- /// Converts this `ScriptBuf` into a [boxed](Box) [`Script`].
+ /// Converts this `GenericScriptBuf` into a [boxed](Box) [`Script`].
///
/// This method reallocates if the capacity is greater than length of the script but should not
/// when they are equal. If you know beforehand that you need to create a script of exact size
@@ -74,7 +74,7 @@ impl ScriptBuf {
/// Constructs a new empty script with at least the specified capacity.
#[inline]
pub fn with_capacity(capacity: usize) -> Self {
- ScriptBuf::from_bytes(Vec::with_capacity(capacity))
+ GenericScriptBuf::from_bytes(Vec::with_capacity(capacity))
}
/// Pre-allocates at least `additional_len` bytes if needed.
@@ -125,24 +125,24 @@ impl ScriptBuf {
pub fn to_hex(&self) -> alloc::string::String { alloc::format!("{:x}", self) }
}
-impl Deref for ScriptBuf {
+impl Deref for GenericScriptBuf {
type Target = Script;
#[inline]
fn deref(&self) -> &Self::Target { self.as_script() }
}
-impl DerefMut for ScriptBuf {
+impl DerefMut for GenericScriptBuf {
#[inline]
fn deref_mut(&mut self) -> &mut Self::Target { self.as_mut_script() }
}
#[cfg(feature = "arbitrary")]
-impl<'a> Arbitrary<'a> for ScriptBuf {
+impl<'a> Arbitrary<'a> for GenericScriptBuf {
#[inline]
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
let v = Vec::<u8>::arbitrary(u)?;
- Ok(ScriptBuf::from_bytes(v))
+ Ok(GenericScriptBuf::from_bytes(v))
}
}
@@ -151,7 +151,7 @@ mod tests {
#[cfg(feature = "alloc")]
use alloc::vec;
- use super::*;
+ use super::super::ScriptBuf;
#[test]
fn script_buf_from_bytes() {
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.