Merge rust-bitcoin/rust-bitcoin#1349: Remove `into_bytes` from `impl_array_newtype`
8c4fa5ec3d
Remove into_bytes from impl_array_newtype (Tobin C. Harding) Pull request description: All the types that we define with `impl_array_newtype` are `Copy` so the correct conversion method to get the underlying byte array is `to_bytes`. We currently provide `into_bytes` as well as `to_bytes`, with one of them calling `clone` - this is unnecessary and against convention. Remove `into_bytes` and for `to_bytes` just return the inner field. Add code comment to remind devs of correct usage of the macro in regards to deriving `Copy` and `Clone`. ACKs for top commit: Kixunil: ACK8c4fa5ec3d
apoelstra: ACK8c4fa5ec3d
Tree-SHA512: 619acbccc5d86afeaea9f69e4b8d4290dcd8d2ccb09d5bb22f475a47f703d63a45c059b0261b1cc3d4c8d9ef0a508263e1e836fd3ba6fa08ff67ebb23eb63309
This commit is contained in:
commit
fb22e5b9c3
|
@ -32,13 +32,16 @@ macro_rules! impl_array_newtype {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn as_bytes(&self) -> &[$ty; $len] { &self.0 }
|
pub fn as_bytes(&self) -> &[$ty; $len] { &self.0 }
|
||||||
|
|
||||||
/// Returns a clone of the underlying bytes.
|
/// Returns the underlying bytes.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn to_bytes(self) -> [$ty; $len] { self.0.clone() }
|
pub fn to_bytes(self) -> [$ty; $len] {
|
||||||
|
// We rely on `Copy` being implemented for $thing so conversion
|
||||||
|
// methods use the correct Rust naming conventions.
|
||||||
|
fn check_copy<T: Copy>() {}
|
||||||
|
check_copy::<$thing>();
|
||||||
|
|
||||||
/// Returns the underlying bytes (takes ownership).
|
self.0
|
||||||
#[inline]
|
}
|
||||||
pub fn into_bytes(self) -> [$ty; $len] { self.0 }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> core::convert::From<&'a [$ty]> for $thing {
|
impl<'a> core::convert::From<&'a [$ty]> for $thing {
|
||||||
|
|
Loading…
Reference in New Issue