stable_hash/impls/
vec.rs

1use crate::prelude::*;
2
3impl<T: StableHash> StableHash for Vec<T> {
4    fn stable_hash<H: StableHasher>(&self, field_address: H::Addr, state: &mut H) {
5        profile_method!(stable_hash);
6
7        (&self[..]).stable_hash(field_address, state)
8    }
9}
10
11impl<'a, T: StableHash> StableHash for &'a [T] {
12    fn stable_hash<H: StableHasher>(&self, field_address: H::Addr, state: &mut H) {
13        profile_method!(stable_hash);
14
15        for (index, item) in self.iter().enumerate() {
16            item.stable_hash(field_address.child(index as u64), state);
17        }
18        // This is needed to disambiguate when the last members are default
19        // For example, vec![true, false] and vec![true, false, false] should
20        // not collide.
21        // See also 33a9b3bf-0d43-4fd0-a3ed-a77807505255
22        self.len().stable_hash(field_address, state);
23    }
24}