1use crate::{Adler32, Adler32Hash};
2
3impl Adler32Hash for &[u8] {
4 fn hash(&self) -> u32 {
5 let mut hash: Adler32 = Adler32::new();
6
7 hash.write(self);
8 hash.finish()
9 }
10}
11
12impl Adler32Hash for &str {
13 fn hash(&self) -> u32 {
14 let mut hash: Adler32 = Adler32::new();
15
16 hash.write(self.as_bytes());
17 hash.finish()
18 }
19}
20
21#[cfg(feature = "const-generics")]
22impl<const SIZE: usize> Adler32Hash for [u8; SIZE] {
23 fn hash(&self) -> u32 {
24 let mut hash: Adler32 = Adler32::new();
25
26 hash.write(self);
27 hash.finish()
28 }
29}
30
31macro_rules! array_impl {
32 ($s:expr, $($size:expr),+) => {
33 array_impl!($s);
34 $(array_impl!{$size})*
35 };
36 ($size:expr) => {
37 #[cfg(not(feature = "const-generics"))]
38 impl Adler32Hash for [u8; $size] {
39 fn hash(&self) -> u32 {
40 let mut hash = Adler32::new();
41
42 hash.write(self);
43 hash.finish()
44 }
45 }
46 };
47}
48
49array_impl!(
50 0,
51 1,
52 2,
53 3,
54 4,
55 5,
56 6,
57 7,
58 8,
59 9,
60 10,
61 11,
62 12,
63 13,
64 14,
65 15,
66 16,
67 17,
68 18,
69 19,
70 20,
71 21,
72 22,
73 23,
74 24,
75 25,
76 26,
77 27,
78 28,
79 29,
80 30,
81 31,
82 32,
83 33,
84 34,
85 35,
86 36,
87 37,
88 38,
89 39,
90 40,
91 41,
92 42,
93 43,
94 44,
95 45,
96 46,
97 47,
98 48,
99 49,
100 50,
101 51,
102 52,
103 53,
104 54,
105 55,
106 56,
107 57,
108 58,
109 59,
110 60,
111 61,
112 62,
113 63,
114 64,
115 65,
116 66,
117 67,
118 68,
119 69,
120 70,
121 71,
122 72,
123 73,
124 74,
125 75,
126 76,
127 77,
128 78,
129 79,
130 80,
131 81,
132 82,
133 83,
134 84,
135 85,
136 86,
137 87,
138 88,
139 89,
140 90,
141 91,
142 92,
143 93,
144 94,
145 95,
146 96,
147 97,
148 98,
149 99,
150 100,
151 1024,
152 1024 * 1024,
153 1024 * 1024 * 1024,
154 2048,
155 4096
156);
157