Skip to content

Commit 3805516

Browse files
Urgaumichaelwoerister
authored andcommitted
Rename StableHasherResult to FromStableHash
1 parent 5185cef commit 3805516

File tree

4 files changed

+18
-17
lines changed

4 files changed

+18
-17
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Unreleased
22

3+
- Rename `StableHasherResult` to `FromStableHash` (#8)
34
- Use new-type for returned-hash of `SipHasher128`(`Hash`) (#8)
45
- Introduce multi hasher support (#8)
56
- `StableHasher::finish` now returns a small hash instead of being fatal (#6)

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub mod hashers {
2323
pub use stable_hasher::StableHasher;
2424

2525
#[doc(inline)]
26-
pub use stable_hasher::StableHasherResult;
26+
pub use stable_hasher::FromStableHash;
2727

2828
#[doc(inline)]
2929
pub use stable_hasher::ExtendedHasher;

src/stable_hasher.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@ pub trait ExtendedHasher: Hasher {
7070
///
7171
/// ```
7272
/// use rustc_stable_hash::hashers::{StableSipHasher128, SipHasher128Hash};
73-
/// use rustc_stable_hash::{StableHasher, StableHasherResult};
73+
/// use rustc_stable_hash::{StableHasher, FromStableHash};
7474
/// use std::hash::Hasher;
7575
///
7676
/// struct Hash128([u64; 2]);
77-
/// impl StableHasherResult for Hash128 {
77+
/// impl FromStableHash for Hash128 {
7878
/// type Hash = SipHasher128Hash;
7979
///
80-
/// fn finish(SipHasher128Hash(hash): SipHasher128Hash) -> Hash128 {
80+
/// fn from(SipHasher128Hash(hash): SipHasher128Hash) -> Hash128 {
8181
/// Hash128(hash)
8282
/// }
8383
/// }
@@ -92,32 +92,32 @@ pub struct StableHasher<H: ExtendedHasher> {
9292
state: H,
9393
}
9494

95-
/// Trait for retrieving the result of the stable hashing operation.
95+
/// Trait for processing the result of the stable hashing operation.
9696
///
9797
/// # Example
9898
///
9999
/// ```
100-
/// use rustc_stable_hash::{StableHasher, StableHasherResult};
100+
/// use rustc_stable_hash::{StableHasher, FromStableHash};
101101
///
102102
/// struct Hash128(u128);
103103
///
104-
/// impl StableHasherResult for Hash128 {
104+
/// impl FromStableHash for Hash128 {
105105
/// type Hash = [u64; 2];
106106
///
107-
/// fn finish(hash: [u64; 2]) -> Hash128 {
107+
/// fn from(hash: [u64; 2]) -> Hash128 {
108108
/// let upper: u128 = hash[0] as u128;
109109
/// let lower: u128 = hash[1] as u128;
110110
///
111111
/// Hash128((upper << 64) | lower)
112112
/// }
113113
/// }
114114
/// ```
115-
pub trait StableHasherResult: Sized {
115+
pub trait FromStableHash: Sized {
116116
type Hash;
117117

118-
/// Retrieving the finalized state of the [`StableHasher`] and construct
119-
/// an [`Self`] containing the hash.
120-
fn finish(hash: Self::Hash) -> Self;
118+
/// Convert the finalized state of a [`StableHasher`] and construct
119+
/// an [`Self`] containing the processed hash.
120+
fn from(hash: Self::Hash) -> Self;
121121
}
122122

123123
impl<H: ExtendedHasher + Default> StableHasher<H> {
@@ -161,13 +161,13 @@ impl<H: ExtendedHasher> StableHasher<H> {
161161
/// Returns the typed-hash value for the values written.
162162
///
163163
/// The resulting typed-hash value is constructed from an
164-
/// [`StableHasherResult`] implemenation.
164+
/// [`FromStableHash`] implemenation.
165165
///
166166
/// To be used in-place of [`Hasher::finish`].
167167
#[inline]
168168
#[must_use]
169-
pub fn finish<W: StableHasherResult<Hash = H::Hash>>(self) -> W {
170-
W::finish(self.state.finish())
169+
pub fn finish<W: FromStableHash<Hash = H::Hash>>(self) -> W {
170+
W::from(self.state.finish())
171171
}
172172
}
173173

src/stable_hasher/tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ use crate::{SipHasher128Hash, StableSipHasher128};
1313
#[derive(Debug, PartialEq)]
1414
struct TestHash([u64; 2]);
1515

16-
impl StableHasherResult for TestHash {
16+
impl FromStableHash for TestHash {
1717
type Hash = SipHasher128Hash;
1818

19-
fn finish(SipHasher128Hash(hash): Self::Hash) -> TestHash {
19+
fn from(SipHasher128Hash(hash): Self::Hash) -> TestHash {
2020
TestHash(hash)
2121
}
2222
}

0 commit comments

Comments
 (0)