@@ -12,6 +12,7 @@ use multihash::Code;
1212use serde:: de:: DeserializeOwned ;
1313use serde:: { Serialize , Serializer } ;
1414
15+ use crate :: error:: EitherError ;
1516use crate :: node:: Node ;
1617use crate :: { Error , Hash , HashAlgorithm , Sha256 , DEFAULT_BIT_WIDTH } ;
1718
@@ -82,12 +83,12 @@ where
8283 }
8384
8485 /// 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 > > {
8687 Self :: load_with_bit_width ( cid, store, DEFAULT_BIT_WIDTH )
8788 }
8889
8990 /// 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 > > {
9192 match store. get_cbor ( cid) ? {
9293 Some ( root) => Ok ( Self {
9394 root,
@@ -100,7 +101,7 @@ where
100101 }
101102
102103 /// 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 > > {
104105 match self . store . get_cbor ( cid) ? {
105106 Some ( root) => self . root = root,
106107 None => return Err ( Error :: CidNotFound ( cid. to_string ( ) ) ) ,
@@ -136,7 +137,7 @@ where
136137 /// map.set(37, "b".to_string()).unwrap();
137138 /// map.set(37, "c".to_string()).unwrap();
138139 /// ```
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 > >
140141 where
141142 V : PartialEq ,
142143 {
@@ -171,7 +172,7 @@ where
171172 /// let c = map.set_if_absent(30, "c".to_string()).unwrap();
172173 /// assert_eq!(c, true);
173174 /// ```
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 > >
175176 where
176177 V : PartialEq ,
177178 {
@@ -200,7 +201,7 @@ where
200201 /// assert_eq!(map.get(&2).unwrap(), None);
201202 /// ```
202203 #[ 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 > >
204205 where
205206 K : Borrow < Q > ,
206207 Q : Hash + Eq ,
@@ -232,7 +233,7 @@ where
232233 /// assert_eq!(map.contains_key(&2).unwrap(), false);
233234 /// ```
234235 #[ 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 > >
236237 where
237238 K : Borrow < Q > ,
238239 Q : Hash + Eq ,
@@ -263,7 +264,7 @@ where
263264 /// assert_eq!(map.delete(&1).unwrap(), Some((1, "a".to_string())));
264265 /// assert_eq!(map.delete(&1).unwrap(), None);
265266 /// ```
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 > >
267268 where
268269 K : Borrow < Q > ,
269270 Q : Hash + Eq ,
@@ -273,7 +274,7 @@ where
273274 }
274275
275276 /// 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 > > {
277278 self . root . flush ( self . store . borrow ( ) ) ?;
278279 Ok ( self . store . put_cbor ( & self . root , Code :: Blake2b256 ) ?)
279280 }
@@ -301,15 +302,15 @@ where
301302 /// let mut total = 0;
302303 /// map.for_each(|_, v: &u64| {
303304 /// total += v;
304- /// Ok(())
305+ /// Ok::<(), ()> (())
305306 /// }).unwrap();
306307 /// assert_eq!(total, 3);
307308 /// ```
308309 #[ 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 > >
310311 where
311312 V : DeserializeOwned ,
312- F : FnMut ( & K , & V ) -> anyhow :: Result < ( ) > ,
313+ F : FnMut ( & K , & V ) -> Result < ( ) , U > ,
313314 {
314315 self . root . for_each ( self . store . borrow ( ) , & mut f)
315316 }
0 commit comments