@@ -12,6 +12,7 @@ use multihash::Code;
12
12
use serde:: de:: DeserializeOwned ;
13
13
use serde:: { Serialize , Serializer } ;
14
14
15
+ use crate :: error:: EitherError ;
15
16
use crate :: node:: Node ;
16
17
use crate :: { Error , Hash , HashAlgorithm , Sha256 , DEFAULT_BIT_WIDTH } ;
17
18
@@ -82,12 +83,12 @@ where
82
83
}
83
84
84
85
/// Lazily instantiate a hamt from this root Cid.
85
- pub fn load ( cid : & Cid , store : BS ) -> Result < Self , Error > {
86
+ pub fn load ( cid : & Cid , store : BS ) -> Result < Self , Error < BS > > {
86
87
Self :: load_with_bit_width ( cid, store, DEFAULT_BIT_WIDTH )
87
88
}
88
89
89
90
/// Lazily instantiate a hamt from this root Cid with a specified bit width.
90
- pub fn load_with_bit_width ( cid : & Cid , store : BS , bit_width : u32 ) -> Result < Self , Error > {
91
+ pub fn load_with_bit_width ( cid : & Cid , store : BS , bit_width : u32 ) -> Result < Self , Error < BS > > {
91
92
match store. get_cbor ( cid) ? {
92
93
Some ( root) => Ok ( Self {
93
94
root,
@@ -100,7 +101,7 @@ where
100
101
}
101
102
102
103
/// Sets the root based on the Cid of the root node using the Hamt store
103
- pub fn set_root ( & mut self , cid : & Cid ) -> Result < ( ) , Error > {
104
+ pub fn set_root ( & mut self , cid : & Cid ) -> Result < ( ) , Error < BS > > {
104
105
match self . store . get_cbor ( cid) ? {
105
106
Some ( root) => self . root = root,
106
107
None => return Err ( Error :: CidNotFound ( cid. to_string ( ) ) ) ,
@@ -136,7 +137,7 @@ where
136
137
/// map.set(37, "b".to_string()).unwrap();
137
138
/// map.set(37, "c".to_string()).unwrap();
138
139
/// ```
139
- pub fn set ( & mut self , key : K , value : V ) -> Result < Option < V > , Error >
140
+ pub fn set ( & mut self , key : K , value : V ) -> Result < Option < V > , Error < BS > >
140
141
where
141
142
V : PartialEq ,
142
143
{
@@ -171,7 +172,7 @@ where
171
172
/// let c = map.set_if_absent(30, "c".to_string()).unwrap();
172
173
/// assert_eq!(c, true);
173
174
/// ```
174
- pub fn set_if_absent ( & mut self , key : K , value : V ) -> Result < bool , Error >
175
+ pub fn set_if_absent ( & mut self , key : K , value : V ) -> Result < bool , Error < BS > >
175
176
where
176
177
V : PartialEq ,
177
178
{
@@ -200,7 +201,7 @@ where
200
201
/// assert_eq!(map.get(&2).unwrap(), None);
201
202
/// ```
202
203
#[ inline]
203
- pub fn get < Q : ?Sized > ( & self , k : & Q ) -> Result < Option < & V > , Error >
204
+ pub fn get < Q : ?Sized > ( & self , k : & Q ) -> Result < Option < & V > , Error < BS > >
204
205
where
205
206
K : Borrow < Q > ,
206
207
Q : Hash + Eq ,
@@ -232,7 +233,7 @@ where
232
233
/// assert_eq!(map.contains_key(&2).unwrap(), false);
233
234
/// ```
234
235
#[ inline]
235
- pub fn contains_key < Q : ?Sized > ( & self , k : & Q ) -> Result < bool , Error >
236
+ pub fn contains_key < Q : ?Sized > ( & self , k : & Q ) -> Result < bool , Error < BS > >
236
237
where
237
238
K : Borrow < Q > ,
238
239
Q : Hash + Eq ,
@@ -263,7 +264,7 @@ where
263
264
/// assert_eq!(map.delete(&1).unwrap(), Some((1, "a".to_string())));
264
265
/// assert_eq!(map.delete(&1).unwrap(), None);
265
266
/// ```
266
- pub fn delete < Q : ?Sized > ( & mut self , k : & Q ) -> Result < Option < ( K , V ) > , Error >
267
+ pub fn delete < Q : ?Sized > ( & mut self , k : & Q ) -> Result < Option < ( K , V ) > , Error < BS > >
267
268
where
268
269
K : Borrow < Q > ,
269
270
Q : Hash + Eq ,
@@ -273,7 +274,7 @@ where
273
274
}
274
275
275
276
/// Flush root and return Cid for hamt
276
- pub fn flush ( & mut self ) -> Result < Cid , Error > {
277
+ pub fn flush ( & mut self ) -> Result < Cid , Error < BS > > {
277
278
self . root . flush ( self . store . borrow ( ) ) ?;
278
279
Ok ( self . store . put_cbor ( & self . root , Code :: Blake2b256 ) ?)
279
280
}
@@ -301,15 +302,15 @@ where
301
302
/// let mut total = 0;
302
303
/// map.for_each(|_, v: &u64| {
303
304
/// total += v;
304
- /// Ok(())
305
+ /// Ok::<(), ()> (())
305
306
/// }).unwrap();
306
307
/// assert_eq!(total, 3);
307
308
/// ```
308
309
#[ inline]
309
- pub fn for_each < F > ( & self , mut f : F ) -> Result < ( ) , Error >
310
+ pub fn for_each < F , U > ( & self , mut f : F ) -> Result < ( ) , EitherError < U , BS > >
310
311
where
311
312
V : DeserializeOwned ,
312
- F : FnMut ( & K , & V ) -> anyhow :: Result < ( ) > ,
313
+ F : FnMut ( & K , & V ) -> Result < ( ) , U > ,
313
314
{
314
315
self . root . for_each ( self . store . borrow ( ) , & mut f)
315
316
}
0 commit comments