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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#[derive(Copy, Clone, PartialEq, Eq, Default, PartialOrd, Ord, Hash, Debug)]
pub struct Hash([u8; 32]);
impl Hash {
pub fn to_array(&self) -> [u8; 32] {
self.0
}
pub fn to_string(&self) -> String {
hex::encode(self.0)
}
}
impl From<String> for Hash {
fn from(hex: String) -> Self {
let raw = hex::decode(hex).unwrap();
Hash::from(raw)
}
}
impl From<&str> for Hash {
fn from(hex: &str) -> Self {
let raw = hex::decode(hex).unwrap();
Hash::from(raw)
}
}
impl From<Vec<u8>> for Hash {
fn from(hex_vec: Vec<u8>) -> Self {
let mut array = [0; 32];
array.copy_from_slice(&hex_vec);
Hash(array)
}
}
impl From<[u8; 32]> for Hash {
fn from(bytes: [u8; 32]) -> Self {
Hash(bytes)
}
}
#[derive(PartialEq, Eq, Clone, Debug, Default)]
pub struct NameHash(Hash);