hashes: Remove to/from/as_raw_hash

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`.
This commit is contained in:
Tobin C. Harding 2024-07-08 14:36:37 +10:00
parent 6c8f759676
commit 2b56f763d0
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
2 changed files with 0 additions and 26 deletions

View File

@ -311,17 +311,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;

View File

@ -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)?))