Skip to main content

newer_type_std/
hash.rs

1use crate::emit_traits;
2use newer_type::target;
3
4emit_traits! {
5    #[implement_of(newer_type_std::hash::Hash)]
6    #[slot(u8)]
7    #[target(alternative = ::core::hash::Hash)]
8    pub trait Hash {
9        fn hash<H>(&self, state: &mut H)
10            where H: ::core::hash::Hasher;
11    }
12
13    #[implement_of(newer_type_std::hash::Hasher)]
14    #[slot(std::collections::hash_map::DefaultHasher)]
15    #[target(alternative = ::core::hash::Hasher)]
16    pub trait Hasher {
17        fn finish(&self) -> ::core::primitive::u64;
18        fn write(&mut self, bytes: &[::core::primitive::u8]);
19        fn write_u8(&mut self, i: ::core::primitive::u8);
20        fn write_u16(&mut self, i: ::core::primitive::u16);
21        fn write_u32(&mut self, i: ::core::primitive::u32);
22        fn write_u64(&mut self, i: ::core::primitive::u64);
23        fn write_u128(&mut self, i: ::core::primitive::u128);
24        fn write_usize(&mut self, i: ::core::primitive::usize);
25        fn write_i8(&mut self, i: ::core::primitive::i8);
26        fn write_i16(&mut self, i: ::core::primitive::i16);
27        fn write_i32(&mut self, i: ::core::primitive::i32);
28        fn write_i64(&mut self, i: ::core::primitive::i64);
29        fn write_i128(&mut self, i: ::core::primitive::i128);
30        fn write_isize(&mut self, i: ::core::primitive::isize);
31    }
32}
33
34#[rustversion::since(1.71)]
35emit_traits! {
36    #[implement_of(newer_type_std::hash::BuildHasher)]
37    #[slot(std::collections::hash_map::RandomState)]
38    #[target(alternative = ::core::hash::BuildHasher)]
39    pub trait BuildHasher {
40        type Hasher: ::core::hash::Hasher;
41        fn build_hasher(&self) -> Self::Hasher;
42
43        fn hash_one<T: ::core::hash::Hash>(&self, x: T) -> ::core::primitive::u64
44        where
45            Self: ::core::marker::Sized,
46            Self::Hasher: ::core::hash::Hasher;
47    }
48}
49
50#[rustversion::before(1.71)]
51emit_traits! {
52    #[implement_of(newer_type_std::hash::BuildHasher)]
53    #[slot(std::collections::hash_map::RandomState)]
54    #[target(alternative = ::core::hash::BuildHasher)]
55    pub trait BuildHasher {
56        type Hasher: ::core::hash::Hasher;
57        fn build_hasher(&self) -> Self::Hasher;
58    }
59}