From 5df8893ea120349b8e58d9c9640fed0dfcd513e4 Mon Sep 17 00:00:00 2001 From: Igor Aleksanov Date: Wed, 16 May 2018 12:31:59 +0300 Subject: [PATCH 1/2] Macro impl_array_newtype now generates method for representing data as array --- src/internal_macros.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/internal_macros.rs b/src/internal_macros.rs index 351693cc..82905b16 100644 --- a/src/internal_macros.rs +++ b/src/internal_macros.rs @@ -77,6 +77,10 @@ macro_rules! impl_array_newtype { #[inline] /// Returns whether the object, as an array, is empty. Always false. pub fn is_empty(&self) -> bool { false } + + #[inline] + /// Returns the underlying data. + pub fn data(&self) -> [$ty; $len] { self.0.clone() } } impl<'a> From<&'a [$ty]> for $thing { From 539a74de12ad4f9c94332f006698d0aa1c9d094d Mon Sep 17 00:00:00 2001 From: Igor Aleksanov Date: Wed, 16 May 2018 12:44:30 +0300 Subject: [PATCH 2/2] Added test for Sha256dHash::data() --- src/util/hash.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/util/hash.rs b/src/util/hash.rs index 9f1d6743..03b5bb80 100644 --- a/src/util/hash.rs +++ b/src/util/hash.rs @@ -481,6 +481,18 @@ mod tests { "56944C5D3F98413EF45CF54545538103CC9F298E0575820AD3591376E2E0F65D"); } + #[test] + fn test_sha256d_data() { + assert_eq!( + Sha256dHash::from_data(&[]).data(), + [ + 0x5d, 0xf6, 0xe0, 0xe2, 0x76, 0x13, 0x59, 0xd3, 0x0a, 0x82, 0x75, 0x05, 0x8e, 0x29, + 0x9f, 0xcc, 0x03, 0x81, 0x53, 0x45, 0x45, 0xf5, 0x5c, 0xf4, 0x3e, 0x41, 0x98, 0x3f, + 0x5d, 0x4c, 0x94, 0x56, + ] + ); + } + #[test] fn sha256d_encoder() { let test = vec![true, false, true, true, false];