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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#[derive(Hash, Eq, PartialEq, Clone)]
pub struct H256([u8;32]);
pub type Address = H256;
pub type StorageKey = H256;
impl From<[u8; 32]> for H256 {
#[inline]
fn from(bytes: [u8; 32]) -> Self {
H256(bytes)
}
}
impl<'a> From<&'a [u8; 32]> for H256 {
#[inline]
fn from(bytes: &'a [u8; 32]) -> Self {
H256(*bytes)
}
}
impl<'a> From<&'a mut [u8; 32]> for H256 {
#[inline]
fn from(bytes: &'a mut [u8; 32]) -> Self {
H256(*bytes)
}
}
impl From<H256> for [u8; 32] {
#[inline]
fn from(s: H256) -> Self {
s.0
}
}
impl AsRef<[u8]> for H256 {
#[inline]
fn as_ref(&self) -> &[u8] {
self.as_bytes()
}
}
impl AsMut<[u8]> for H256 {
#[inline]
fn as_mut(&mut self) -> &mut [u8] {
self.as_bytes_mut()
}
}
impl H256 {
#[inline]
pub fn repeat_byte(byte: u8) -> H256 {
H256([byte; 32])
}
#[inline]
pub fn zero() -> H256 {
H256::repeat_byte(0u8)
}
#[inline]
pub fn len_bytes() -> usize {
32
}
#[inline]
pub fn as_bytes(&self) -> &[u8] {
&self.0
}
#[inline]
pub fn as_bytes_mut(&mut self) -> &mut [u8] {
&mut self.0
}
#[inline]
pub fn as_fixed_bytes(&self) -> &[u8; 32] {
&self.0
}
#[inline]
pub fn copy_to_array(&self, target: &mut [u8; 32]) {
target.copy_from_slice(&self.0[..]);
}
}