@@ -18,7 +18,6 @@ use kvdb::{DBTransaction, KeyValueDB};
1818use parking_lot:: RwLock ;
1919use std:: collections:: HashMap ;
2020use std:: hash:: Hash ;
21- use std:: ops:: Deref ;
2221
2322// database columns
2423/// Column for State
7776/// Should be used to get database key associated with given value.
7877pub trait Key < T > {
7978 /// The db key associated with this value.
80- type Target : Deref < Target = [ u8 ] > ;
79+ type Target : AsRef < [ u8 ] > ;
8180
8281 /// Returns db key.
8382 fn key ( & self ) -> Self :: Target ;
@@ -89,13 +88,13 @@ pub trait Writable {
8988 fn write < T , R > ( & mut self , col : Option < u32 > , key : & dyn Key < T , Target = R > , value : & T )
9089 where
9190 T : rlp:: Encodable ,
92- R : Deref < Target = [ u8 ] > ;
91+ R : AsRef < [ u8 ] > ;
9392
9493 /// Deletes key from the databse.
9594 fn delete < T , R > ( & mut self , col : Option < u32 > , key : & dyn Key < T , Target = R > )
9695 where
9796 T : rlp:: Encodable ,
98- R : Deref < Target = [ u8 ] > ;
97+ R : AsRef < [ u8 ] > ;
9998
10099 /// Writes the value into the database and updates the cache.
101100 fn write_with_cache < K , T , R > (
@@ -108,7 +107,7 @@ pub trait Writable {
108107 ) where
109108 K : Key < T , Target = R > + Hash + Eq ,
110109 T : rlp:: Encodable ,
111- R : Deref < Target = [ u8 ] > , {
110+ R : AsRef < [ u8 ] > , {
112111 self . write ( col, & key, & value) ;
113112 match policy {
114113 CacheUpdatePolicy :: Overwrite => {
@@ -130,7 +129,7 @@ pub trait Writable {
130129 ) where
131130 K : Key < T , Target = R > + Hash + Eq ,
132131 T : rlp:: Encodable ,
133- R : Deref < Target = [ u8 ] > , {
132+ R : AsRef < [ u8 ] > , {
134133 match policy {
135134 CacheUpdatePolicy :: Overwrite => {
136135 for ( key, value) in values {
@@ -154,7 +153,7 @@ pub trait Readable {
154153 fn read < T , R > ( & self , col : Option < u32 > , key : & dyn Key < T , Target = R > ) -> Option < T >
155154 where
156155 T : rlp:: Decodable ,
157- R : Deref < Target = [ u8 ] > ;
156+ R : AsRef < [ u8 ] > ;
158157
159158 /// Returns value for given key either in cache or in database.
160159 fn read_with_cache < K , T , C > ( & self , col : Option < u32 > , cache : & mut C , key : & K ) -> Option < T >
@@ -177,13 +176,13 @@ pub trait Readable {
177176 /// Returns true if given value exists.
178177 fn exists < T , R > ( & self , col : Option < u32 > , key : & dyn Key < T , Target = R > ) -> bool
179178 where
180- R : Deref < Target = [ u8 ] > ;
179+ R : AsRef < [ u8 ] > ;
181180
182181 /// Returns true if given value exists either in cache or in database.
183182 fn exists_with_cache < K , T , R , C > ( & self , col : Option < u32 > , cache : & RwLock < C > , key : & K ) -> bool
184183 where
185184 K : Eq + Hash + Key < T , Target = R > ,
186- R : Deref < Target = [ u8 ] > ,
185+ R : AsRef < [ u8 ] > ,
187186 C : Cache < K , T > , {
188187 {
189188 let read = cache. read ( ) ;
@@ -200,42 +199,42 @@ impl Writable for DBTransaction {
200199 fn write < T , R > ( & mut self , col : Option < u32 > , key : & dyn Key < T , Target = R > , value : & T )
201200 where
202201 T : rlp:: Encodable ,
203- R : Deref < Target = [ u8 ] > , {
204- self . put ( col, & key. key ( ) , & rlp:: encode ( value) ) ;
202+ R : AsRef < [ u8 ] > , {
203+ self . put ( col, key. key ( ) . as_ref ( ) , & rlp:: encode ( value) ) ;
205204 }
206205
207206 fn delete < T , R > ( & mut self , col : Option < u32 > , key : & dyn Key < T , Target = R > )
208207 where
209208 T : rlp:: Encodable ,
210- R : Deref < Target = [ u8 ] > , {
211- self . delete ( col, & key. key ( ) ) ;
209+ R : AsRef < [ u8 ] > , {
210+ self . delete ( col, key. key ( ) . as_ref ( ) ) ;
212211 }
213212}
214213
215214impl < KVDB : KeyValueDB + ?Sized > Readable for KVDB {
216215 fn read < T , R > ( & self , col : Option < u32 > , key : & dyn Key < T , Target = R > ) -> Option < T >
217216 where
218217 T : rlp:: Decodable ,
219- R : Deref < Target = [ u8 ] > , {
220- let result = self . get ( col, & key. key ( ) ) ;
218+ R : AsRef < [ u8 ] > , {
219+ let result = self . get ( col, key. key ( ) . as_ref ( ) ) ;
221220
222221 match result {
223222 Ok ( option) => option. map ( |v| rlp:: decode ( & v) . unwrap ( ) ) ,
224223 Err ( err) => {
225- panic ! ( "db get failed, key: {:?}, err: {:?}" , & key. key( ) as & [ u8 ] , err) ;
224+ panic ! ( "db get failed, key: {:?}, err: {:?}" , key. key( ) . as_ref ( ) , err) ;
226225 }
227226 }
228227 }
229228
230229 fn exists < T , R > ( & self , col : Option < u32 > , key : & dyn Key < T , Target = R > ) -> bool
231230 where
232- R : Deref < Target = [ u8 ] > , {
233- let result = self . get ( col, & key. key ( ) ) ;
231+ R : AsRef < [ u8 ] > , {
232+ let result = self . get ( col, key. key ( ) . as_ref ( ) ) ;
234233
235234 match result {
236235 Ok ( v) => v. is_some ( ) ,
237236 Err ( err) => {
238- panic ! ( "db get failed, key: {:?}, err: {:?}" , & key. key( ) as & [ u8 ] , err) ;
237+ panic ! ( "db get failed, key: {:?}, err: {:?}" , key. key( ) . as_ref ( ) , err) ;
239238 }
240239 }
241240 }
0 commit comments