1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use crate::prelude::*;

pub trait UnorderedAggregator<T> {
    fn write(&mut self, value: impl StableHash, sequence_number: T);
}

/// Like Hasher, but consistent across:
/// * builds (independent of rustc version or std implementation details)
/// * platforms (eg: 32 bit & 64 bit, x68 and ARM)
/// * processes (multiple runs of the same program)
pub trait StableHasher {
    type Out;
    type Seq: SequenceNumber;
    type Unordered: UnorderedAggregator<Self::Seq>;
    fn write(&mut self, sequence_number: Self::Seq, bytes: &[u8]);
    fn start_unordered(&mut self) -> Self::Unordered;
    fn finish_unordered(&mut self, unordered: Self::Unordered, sequence_number: Self::Seq);
    fn finish(&self) -> Self::Out;
}

/// Like Hash, but consistent across:
/// * builds (independent of rustc version or std implementation details)
/// * platforms (eg: 32 bit & 64 bit, x68 and ARM)
/// * processes (multiple runs of the same program)
pub trait StableHash {
    fn stable_hash<H: StableHasher>(&self, sequence_number: H::Seq, state: &mut H);
}