@@ -134,8 +134,7 @@ use anybytes::area::SectionWriter;
134134use anybytes:: Bytes ;
135135use anybytes:: View ;
136136
137- use anyhow:: anyhow;
138- use anyhow:: Result ;
137+ use crate :: error:: { Error , Result } ;
139138
140139/// Builder that collects raw bits into a zero-copy [`BitVector`].
141140
@@ -189,10 +188,10 @@ impl<'a> BitVectorBuilder<'a> {
189188 /// Returns the `pos`-th bit.
190189 pub fn get_bit ( & self , pos : usize ) -> Result < bool > {
191190 if self . len <= pos {
192- return Err ( anyhow ! (
191+ return Err ( Error :: invalid_argument ( format ! (
193192 "pos must be no greater than self.len()={}, but got {pos}." ,
194193 self . len
195- ) ) ;
194+ ) ) ) ;
196195 }
197196 let word = pos / WORD_LEN ;
198197 let pos_in_word = pos % WORD_LEN ;
@@ -202,10 +201,10 @@ impl<'a> BitVectorBuilder<'a> {
202201 /// Sets the `pos`-th bit to `bit`.
203202 pub fn set_bit ( & mut self , pos : usize , bit : bool ) -> Result < ( ) > {
204203 if self . len <= pos {
205- return Err ( anyhow ! (
204+ return Err ( Error :: invalid_argument ( format ! (
206205 "pos must be no greater than self.len()={}, but got {pos}." ,
207206 self . len
208- ) ) ;
207+ ) ) ) ;
209208 }
210209 let word = pos / WORD_LEN ;
211210 let pos_in_word = pos % WORD_LEN ;
@@ -217,11 +216,10 @@ impl<'a> BitVectorBuilder<'a> {
217216 /// Sets all bits in `range` to `bit`.
218217 pub fn set_bits ( & mut self , range : std:: ops:: Range < usize > , bit : bool ) -> Result < ( ) > {
219218 if range. end > self . len {
220- return Err ( anyhow ! (
219+ return Err ( Error :: invalid_argument ( format ! (
221220 "range end must be no greater than self.len()={}, but got {}." ,
222- self . len,
223- range. end
224- ) ) ;
221+ self . len, range. end
222+ ) ) ) ;
225223 }
226224 if range. is_empty ( ) {
227225 return Ok ( ( ) ) ;
@@ -250,10 +248,10 @@ impl<'a> BitVectorBuilder<'a> {
250248 /// Swaps bits at positions `a` and `b`.
251249 pub fn swap_bits ( & mut self , a : usize , b : usize ) -> Result < ( ) > {
252250 if a >= self . len || b >= self . len {
253- return Err ( anyhow ! (
251+ return Err ( Error :: invalid_argument ( format ! (
254252 "positions must be less than self.len()={}, but got {a} and {b}." ,
255253 self . len
256- ) ) ;
254+ ) ) ) ;
257255 }
258256 if a == b {
259257 return Ok ( ( ) ) ;
@@ -284,11 +282,10 @@ impl<'a> BitVectorBuilder<'a> {
284282 I : Iterator < Item = bool > ,
285283 {
286284 if start > self . len {
287- return Err ( anyhow ! (
285+ return Err ( Error :: invalid_argument ( format ! (
288286 "start must be no greater than self.len()={}, but got {}." ,
289- self . len,
290- start
291- ) ) ;
287+ self . len, start
288+ ) ) ) ;
292289 }
293290 let mut pos = start;
294291 while pos < self . len {
@@ -390,7 +387,7 @@ impl BitVectorData {
390387
391388 /// Reconstructs the data from zero-copy [`Bytes`] and its metadata.
392389 pub fn from_bytes ( meta : BitVectorDataMeta , bytes : Bytes ) -> Result < Self > {
393- let words = meta. handle . view ( & bytes) . map_err ( |e| anyhow :: anyhow! ( e ) ) ?;
390+ let words = meta. handle . view ( & bytes) ?;
394391 Ok ( Self {
395392 words,
396393 len : meta. len ,
@@ -439,6 +436,7 @@ impl BitVectorData {
439436
440437impl Serializable for BitVectorData {
441438 type Meta = BitVectorDataMeta ;
439+ type Error = Error ;
442440
443441 fn metadata ( & self ) -> Self :: Meta {
444442 BitVectorData :: metadata ( self )
@@ -700,6 +698,7 @@ impl<I: BitVectorIndex> BitVector<I> {
700698
701699impl < I : BitVectorIndex > Serializable for BitVector < I > {
702700 type Meta = BitVectorDataMeta ;
701+ type Error = Error ;
703702
704703 fn metadata ( & self ) -> Self :: Meta {
705704 self . data . metadata ( )
0 commit comments