Add to_vec and deprecate to_bytes for array types

For the array wrapper types (eg `ShortId`) created with the
`impl_array_newtype` macro deprecated the `to_bytes` function and add a
`to_vec` function.

Discussed and decided upon in issue: #3025
This commit is contained in:
Tobin C. Harding 2024-10-31 14:19:03 +11:00
parent a6b7ab32a8
commit dc2ca785d2
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
1 changed files with 6 additions and 1 deletions

View File

@ -300,13 +300,18 @@ macro_rules! impl_array_newtype {
self.0 self.0
} }
/// Copies the underlying bytes into a new `Vec`.
#[inline]
pub fn to_vec(&self) -> alloc::vec::Vec<u8> { self.0.to_vec() }
/// Returns a slice of the underlying bytes. /// Returns a slice of the underlying bytes.
#[inline] #[inline]
pub fn as_bytes(&self) -> &[u8] { &self.0 } pub fn as_bytes(&self) -> &[u8] { &self.0 }
/// Copies the underlying bytes into a new `Vec`. /// Copies the underlying bytes into a new `Vec`.
#[inline] #[inline]
pub fn to_bytes(&self) -> alloc::vec::Vec<u8> { self.0.to_vec() } #[deprecated(since = "TBD", note = "use to_vec instead")]
pub fn to_bytes(&self) -> alloc::vec::Vec<u8> { self.to_vec() }
/// Converts the object to a raw pointer. /// Converts the object to a raw pointer.
#[inline] #[inline]