Merge rust-bitcoin/rust-bitcoin#2981: Remove to/from/as_raw_hash functions
2b56f763d0
hashes: Remove to/from/as_raw_hash (Tobin C. Harding) Pull request description: In an effort to shrink the API of `hashes` remove the `from_raw_hash`, `to_raw_hash`, and `as_raw_hash` inherent functions from types created with the `hash_newtype` macro. There are a few reasons why this is favourable: - It allows stable crates to use the macro and not expose unstable `hashes` types in their API. - It makes types created with the macro less "general" in the sense that its more obscure to just hash any data into them. This allows us to write cleaner APIs in `rust-bitcoin`. ACKs for top commit: Kixunil: ACK2b56f763d0
apoelstra: ACK2b56f763d0
Tree-SHA512: 3d73aa8250dd775994623c9201dd819256acf2ec82526b3537da74c9e19c2ac5e8bba358a2171f7b02342804cb6b4d5ac4dca88d912b3d46d14e3bc35dd5cb91
This commit is contained in:
commit
c50796c238
|
@ -304,17 +304,6 @@ mod tests {
|
|||
0x15, 0x26, 0x37, 0x48, 0x59, 0x6a, 0x7b, 0x8c,
|
||||
]);
|
||||
|
||||
#[test]
|
||||
fn convert_newtypes() {
|
||||
let h1 = DUMMY;
|
||||
let h2: TestNewtype2 = h1.to_raw_hash().into();
|
||||
assert_eq!(&h1[..], &h2[..]);
|
||||
|
||||
let h = sha256d::Hash::hash(&[]);
|
||||
let h2: TestNewtype = h.to_string().parse().unwrap();
|
||||
assert_eq!(h2.to_raw_hash(), h);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn newtype_fmt_roundtrip() {
|
||||
let orig = DUMMY;
|
||||
|
|
|
@ -194,21 +194,6 @@ macro_rules! hash_newtype {
|
|||
|
||||
#[allow(unused)] // Private wrapper types may not need all functions.
|
||||
impl $newtype {
|
||||
/// Creates this wrapper type from the inner hash type.
|
||||
pub const fn from_raw_hash(inner: $hash) -> $newtype {
|
||||
$newtype(inner)
|
||||
}
|
||||
|
||||
/// Returns the inner hash (sha256, sh256d etc.).
|
||||
pub const fn to_raw_hash(self) -> $hash {
|
||||
self.0
|
||||
}
|
||||
|
||||
/// Returns a reference to the inner hash (sha256, sh256d etc.).
|
||||
pub const fn as_raw_hash(&self) -> &$hash {
|
||||
&self.0
|
||||
}
|
||||
|
||||
/// Copies a byte slice into a hash object.
|
||||
pub fn from_slice(sl: &[u8]) -> $crate::_export::_core::result::Result<$newtype, $crate::FromSliceError> {
|
||||
Ok($newtype(<$hash as $crate::Hash>::from_slice(sl)?))
|
||||
|
|
Loading…
Reference in New Issue