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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(not(feature = "std"), feature(core_intrinsics))]
#[cfg(feature = "std")]
use std::fmt::Debug;
#[cfg(feature = "std")]
use std::hash;
#[cfg(feature = "std")]
pub trait MaybeDebug: Debug {}
#[cfg(feature = "std")]
impl<T: Debug> MaybeDebug for T {}
#[cfg(not(feature = "std"))]
use core::hash;
#[cfg(not(feature = "std"))]
pub trait MaybeDebug {}
#[cfg(not(feature = "std"))]
impl<T> MaybeDebug for T {}
pub static EMPTY_PREFIX: Prefix<'static> = &[];
pub type Prefix<'a> = &'a[u8];
pub trait Hasher: Sync + Send {
type Out: AsRef<[u8]> + AsMut<[u8]> + Default + MaybeDebug + PartialEq + Eq + hash::Hash + Send + Sync + Clone + Copy;
type StdHasher: Sync + Send + Default + hash::Hasher;
const LENGTH: usize;
fn hash(x: &[u8]) -> Self::Out;
}
pub trait PlainDB<K, V>: Send + Sync + AsPlainDB<K, V> {
fn get(&self, key: &K) -> Option<V>;
fn contains(&self, key: &K) -> bool;
fn emplace(&mut self, key: K, value: V);
fn remove(&mut self, key: &K);
}
pub trait PlainDBRef<K, V> {
fn get(&self, key: &K) -> Option<V>;
fn contains(&self, key: &K) -> bool;
}
impl<'a, K, V> PlainDBRef<K, V> for &'a dyn PlainDB<K, V> {
fn get(&self, key: &K) -> Option<V> { PlainDB::get(*self, key) }
fn contains(&self, key: &K) -> bool { PlainDB::contains(*self, key) }
}
impl<'a, K, V> PlainDBRef<K, V> for &'a mut dyn PlainDB<K, V> {
fn get(&self, key: &K) -> Option<V> { PlainDB::get(*self, key) }
fn contains(&self, key: &K) -> bool { PlainDB::contains(*self, key) }
}
pub trait HashDB<H: Hasher, T>: Send + Sync + AsHashDB<H, T> {
fn get(&self, key: &H::Out, prefix: &[u8]) -> Option<T>;
fn contains(&self, key: &H::Out, prefix: &[u8]) -> bool;
fn insert(&mut self, prefix: &[u8], value: &[u8]) -> H::Out;
fn emplace(&mut self, key: H::Out, prefix: &[u8], value: T);
fn remove(&mut self, key: &H::Out, prefix: &[u8]);
}
pub trait HashDBRef<H: Hasher, T> {
fn get(&self, key: &H::Out, prefix: &[u8]) -> Option<T>;
fn contains(&self, key: &H::Out, prefix: &[u8]) -> bool;
}
impl<'a, H: Hasher, T> HashDBRef<H, T> for &'a dyn HashDB<H, T> {
fn get(&self, key: &H::Out, prefix: &[u8]) -> Option<T> { HashDB::get(*self, key, prefix) }
fn contains(&self, key: &H::Out, prefix: &[u8]) -> bool { HashDB::contains(*self, key, prefix) }
}
impl<'a, H: Hasher, T> HashDBRef<H, T> for &'a mut dyn HashDB<H, T> {
fn get(&self, key: &H::Out, prefix: &[u8]) -> Option<T> { HashDB::get(*self, key, prefix) }
fn contains(&self, key: &H::Out, prefix: &[u8]) -> bool { HashDB::contains(*self, key, prefix) }
}
pub trait AsHashDB<H: Hasher, T> {
fn as_hash_db(&self) -> &dyn HashDB<H, T>;
fn as_hash_db_mut<'a>(&'a mut self) -> &'a mut (dyn HashDB<H, T> + 'a);
}
pub trait AsPlainDB<K, V> {
fn as_plain_db(&self) -> &dyn PlainDB<K, V>;
fn as_plain_db_mut<'a>(&'a mut self) -> &'a mut (dyn PlainDB<K, V> + 'a);
}
impl<'a, H: Hasher, T> AsHashDB<H, T> for &'a mut dyn HashDB<H, T> {
fn as_hash_db(&self) -> &dyn HashDB<H, T> { &**self }
fn as_hash_db_mut<'b>(&'b mut self) -> &'b mut (dyn HashDB<H, T> + 'b) { &mut **self }
}
#[cfg(feature = "std")]
impl<'a, K, V> AsPlainDB<K, V> for &'a mut PlainDB<K, V> {
fn as_plain_db(&self) -> &PlainDB<K, V> { &**self }
fn as_plain_db_mut<'b>(&'b mut self) -> &'b mut (PlainDB<K, V> + 'b) { &mut **self }
}