Deprecate to_vec in favour of to_bytes

Currently we have to method names for the same thing "copy this object
into a vector". The library is easier to use if we are uniform and just
use one.

Elect to use `to_bytes`, for context see discussion in PR #2585.
This commit is contained in:
Tobin C. Harding 2024-05-14 10:47:02 +10:00
parent 89d6991cf1
commit eda61ddfef
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
3 changed files with 15 additions and 3 deletions

View File

@ -284,7 +284,11 @@ impl Witness {
} }
/// Convenience method to create an array of byte-arrays from this witness. /// Convenience method to create an array of byte-arrays from this witness.
pub fn to_vec(&self) -> Vec<Vec<u8>> { self.iter().map(|s| s.to_vec()).collect() } pub fn to_bytes(&self) -> Vec<Vec<u8>> { self.iter().map(|s| s.to_vec()).collect() }
/// Convenience method to create an array of byte-arrays from this witness.
#[deprecated(since = "TBD", note = "Use to_bytes instead")]
pub fn to_vec(&self) -> Vec<Vec<u8>> { self.to_bytes() }
/// Returns `true` if the witness contains no element. /// Returns `true` if the witness contains no element.
pub fn is_empty(&self) -> bool { self.witness_elements == 0 } pub fn is_empty(&self) -> bool { self.witness_elements == 0 }

View File

@ -57,7 +57,7 @@ impl Signature {
/// ///
/// Note: this performs an extra heap allocation, you might prefer the /// Note: this performs an extra heap allocation, you might prefer the
/// [`serialize`](Self::serialize) method instead. /// [`serialize`](Self::serialize) method instead.
pub fn to_vec(self) -> Vec<u8> { pub fn to_bytes(self) -> Vec<u8> {
self.signature self.signature
.serialize_der() .serialize_der()
.iter() .iter()
@ -66,6 +66,10 @@ impl Signature {
.collect() .collect()
} }
/// Serializes an ECDSA signature (inner secp256k1 signature in DER format) into `Vec`.
#[deprecated(since = "TBD", note = "Use to_bytes instead")]
pub fn to_vec(self) -> Vec<u8> { self.to_bytes() }
/// Serializes an ECDSA signature (inner secp256k1 signature in DER format) to a `writer`. /// Serializes an ECDSA signature (inner secp256k1 signature in DER format) to a `writer`.
#[inline] #[inline]
pub fn serialize_to_writer<W: Write + ?Sized>(&self, writer: &mut W) -> Result<(), io::Error> { pub fn serialize_to_writer<W: Write + ?Sized>(&self, writer: &mut W) -> Result<(), io::Error> {

View File

@ -47,7 +47,7 @@ impl Signature {
/// Serialize Signature /// Serialize Signature
/// ///
/// Note: this allocates on the heap, prefer [`serialize`](Self::serialize) if vec is not needed. /// Note: this allocates on the heap, prefer [`serialize`](Self::serialize) if vec is not needed.
pub fn to_vec(self) -> Vec<u8> { pub fn to_bytes(self) -> Vec<u8> {
let mut ser_sig = self.signature.as_ref().to_vec(); let mut ser_sig = self.signature.as_ref().to_vec();
if self.sighash_type == TapSighashType::Default { if self.sighash_type == TapSighashType::Default {
// default sighash type, don't add extra sighash byte // default sighash type, don't add extra sighash byte
@ -57,6 +57,10 @@ impl Signature {
ser_sig ser_sig
} }
/// Serialize Signature
#[deprecated(since = "TBD", note = "Use to_bytes instead")]
pub fn to_vec(self) -> Vec<u8> { self.to_bytes() }
/// Serializes the signature to `writer`. /// Serializes the signature to `writer`.
#[inline] #[inline]
pub fn serialize_to_writer<W: Write + ?Sized>(&self, writer: &mut W) -> Result<(), io::Error> { pub fn serialize_to_writer<W: Write + ?Sized>(&self, writer: &mut W) -> Result<(), io::Error> {