Move `Deref{Mut}` from common module to `owned`

We have several trait implementations for `Script` and `ScriptBuf` in a
common module so that it's easy to verify that they are same but `Deref`
and `DerefMut` should *not* be implemented for `Script` so having them
in the common module is not helpful. This moves them to the appropriate
`Owned` module.
This commit is contained in:
Martin Habovstiak 2025-02-20 15:54:25 +01:00
parent 3b15e900f0
commit bca2864084
2 changed files with 11 additions and 13 deletions

View File

@ -10,7 +10,6 @@ mod owned;
use core::cmp::Ordering;
use core::convert::Infallible;
use core::fmt;
use core::ops::{Deref, DerefMut};
use hashes::{hash160, sha256};
use hex::DisplayHex;
@ -415,16 +414,6 @@ impl fmt::UpperHex for ScriptBuf {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::UpperHex::fmt(self.as_script(), f) }
}
impl Deref for ScriptBuf {
type Target = Script;
fn deref(&self) -> &Self::Target { self.as_script() }
}
impl DerefMut for ScriptBuf {
fn deref_mut(&mut self) -> &mut Self::Target { self.as_mut_script() }
}
impl Borrow<Script> for ScriptBuf {
fn borrow(&self) -> &Script { self }
}

View File

@ -1,7 +1,6 @@
// SPDX-License-Identifier: CC0-1.0
#[cfg(doc)]
use core::ops::Deref;
use core::ops::{Deref, DerefMut};
#[cfg(feature = "arbitrary")]
use arbitrary::{Arbitrary, Unstructured};
@ -87,6 +86,16 @@ impl ScriptBuf {
pub fn reserve_exact(&mut self, additional_len: usize) { self.0.reserve_exact(additional_len); }
}
impl Deref for ScriptBuf {
type Target = Script;
fn deref(&self) -> &Self::Target { self.as_script() }
}
impl DerefMut for ScriptBuf {
fn deref_mut(&mut self) -> &mut Self::Target { self.as_mut_script() }
}
#[cfg(feature = "arbitrary")]
impl<'a> Arbitrary<'a> for ScriptBuf {
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {