Refer to `Script{Buf}` as `Self` where relevant
Using `Self` instead of specific type name can make some refactorings easier.
This commit is contained in:
parent
ce55dd5b70
commit
5680b4e870
|
@ -74,28 +74,28 @@ impl ToOwned for Script {
|
|||
impl Script {
|
||||
/// Constructs a new empty script.
|
||||
#[inline]
|
||||
pub const fn new() -> &'static Script { Script::from_bytes(&[]) }
|
||||
pub const fn new() -> &'static Self { Self::from_bytes(&[]) }
|
||||
|
||||
/// Treat byte slice as `Script`
|
||||
#[inline]
|
||||
pub const fn from_bytes(bytes: &[u8]) -> &Script {
|
||||
pub const fn from_bytes(bytes: &[u8]) -> &Self {
|
||||
// SAFETY: copied from `std`
|
||||
// The pointer was just created from a reference which is still alive.
|
||||
// Casting slice pointer to a transparent struct wrapping that slice is sound (same
|
||||
// layout).
|
||||
unsafe { &*(bytes as *const [u8] as *const Script) }
|
||||
unsafe { &*(bytes as *const [u8] as *const Self) }
|
||||
}
|
||||
|
||||
/// Treat mutable byte slice as `Script`
|
||||
#[inline]
|
||||
pub fn from_bytes_mut(bytes: &mut [u8]) -> &mut Script {
|
||||
pub fn from_bytes_mut(bytes: &mut [u8]) -> &mut Self {
|
||||
// SAFETY: copied from `std`
|
||||
// The pointer was just created from a reference which is still alive.
|
||||
// Casting slice pointer to a transparent struct wrapping that slice is sound (same
|
||||
// layout).
|
||||
// Function signature prevents callers from accessing `bytes` while the returned reference
|
||||
// is alive.
|
||||
unsafe { &mut *(bytes as *mut [u8] as *mut Script) }
|
||||
unsafe { &mut *(bytes as *mut [u8] as *mut Self) }
|
||||
}
|
||||
|
||||
/// Returns the script data as a byte slice.
|
||||
|
|
|
@ -299,7 +299,7 @@ impl From<ScriptBuf> for Vec<u8> {
|
|||
|
||||
impl AsRef<Script> for Script {
|
||||
#[inline]
|
||||
fn as_ref(&self) -> &Script { self }
|
||||
fn as_ref(&self) -> &Self { self }
|
||||
}
|
||||
|
||||
impl AsRef<Script> for ScriptBuf {
|
||||
|
@ -319,7 +319,7 @@ impl AsRef<[u8]> for ScriptBuf {
|
|||
|
||||
impl AsMut<Script> for Script {
|
||||
#[inline]
|
||||
fn as_mut(&mut self) -> &mut Script { self }
|
||||
fn as_mut(&mut self) -> &mut Self { self }
|
||||
}
|
||||
|
||||
impl AsMut<Script> for ScriptBuf {
|
||||
|
@ -435,14 +435,14 @@ impl fmt::LowerHex for Script {
|
|||
}
|
||||
}
|
||||
#[cfg(feature = "alloc")]
|
||||
internals::impl_to_hex_from_lower_hex!(Script, |script: &Script| script.len() * 2);
|
||||
internals::impl_to_hex_from_lower_hex!(Script, |script: &Self| script.len() * 2);
|
||||
|
||||
impl fmt::LowerHex for ScriptBuf {
|
||||
#[inline]
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::LowerHex::fmt(self.as_script(), f) }
|
||||
}
|
||||
#[cfg(feature = "alloc")]
|
||||
internals::impl_to_hex_from_lower_hex!(ScriptBuf, |script_buf: &ScriptBuf| script_buf.len() * 2);
|
||||
internals::impl_to_hex_from_lower_hex!(ScriptBuf, |script_buf: &Self| script_buf.len() * 2);
|
||||
|
||||
impl fmt::UpperHex for Script {
|
||||
#[inline]
|
||||
|
|
|
@ -23,13 +23,13 @@ pub struct ScriptBuf(Vec<u8>);
|
|||
impl ScriptBuf {
|
||||
/// Constructs a new empty script.
|
||||
#[inline]
|
||||
pub const fn new() -> Self { ScriptBuf::from_bytes(Vec::new()) }
|
||||
pub const fn new() -> Self { Self::from_bytes(Vec::new()) }
|
||||
|
||||
/// Converts byte vector into script.
|
||||
///
|
||||
/// This method doesn't (re)allocate.
|
||||
#[inline]
|
||||
pub const fn from_bytes(bytes: Vec<u8>) -> Self { ScriptBuf(bytes) }
|
||||
pub const fn from_bytes(bytes: Vec<u8>) -> Self { Self(bytes) }
|
||||
|
||||
/// Returns a reference to unsized script.
|
||||
#[inline]
|
||||
|
|
Loading…
Reference in New Issue