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:
parent
6c8f759676
commit
2b56f763d0
|
@ -311,17 +311,6 @@ mod tests {
|
||||||
0x15, 0x26, 0x37, 0x48, 0x59, 0x6a, 0x7b, 0x8c,
|
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]
|
#[test]
|
||||||
fn newtype_fmt_roundtrip() {
|
fn newtype_fmt_roundtrip() {
|
||||||
let orig = DUMMY;
|
let orig = DUMMY;
|
||||||
|
|
|
@ -194,21 +194,6 @@ macro_rules! hash_newtype {
|
||||||
|
|
||||||
#[allow(unused)] // Private wrapper types may not need all functions.
|
#[allow(unused)] // Private wrapper types may not need all functions.
|
||||||
impl $newtype {
|
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.
|
/// Copies a byte slice into a hash object.
|
||||||
pub fn from_slice(sl: &[u8]) -> $crate::_export::_core::result::Result<$newtype, $crate::FromSliceError> {
|
pub fn from_slice(sl: &[u8]) -> $crate::_export::_core::result::Result<$newtype, $crate::FromSliceError> {
|
||||||
Ok($newtype(<$hash as $crate::Hash>::from_slice(sl)?))
|
Ok($newtype(<$hash as $crate::Hash>::from_slice(sl)?))
|
||||||
|
|
Loading…
Reference in New Issue