File tree Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,24 @@ pub struct Guard {
3232}
3333
3434impl IterGuard for Guard {
35+ fn into_inner_if ( self , pred : impl Fn ( & [ u8 ] ) -> bool ) -> crate :: Result < Option < crate :: KvPair > > {
36+ let kv = self . kv ?;
37+
38+ if pred ( & kv. key . user_key ) {
39+ resolve_value_handle (
40+ self . tree . id ( ) ,
41+ self . tree . blobs_folder . as_path ( ) ,
42+ & self . tree . index . config . cache ,
43+ & self . tree . index . config . descriptor_table ,
44+ & self . version ,
45+ kv,
46+ )
47+ . map ( Some )
48+ } else {
49+ Ok ( None )
50+ }
51+ }
52+
3553 fn key ( self ) -> crate :: Result < UserKey > {
3654 self . kv . map ( |kv| kv. key . user_key )
3755 }
Original file line number Diff line number Diff line change @@ -6,6 +6,16 @@ use enum_dispatch::enum_dispatch;
66/// Guard to access key-value pairs
77#[ enum_dispatch]
88pub trait IterGuard {
9+ /// Accesses the key-value pair if the predicate returns `true`.
10+ ///
11+ /// The predicate receives the key - if returning false, the value
12+ /// may not be loaded if the tree is key-value separated.
13+ ///
14+ /// # Errors
15+ ///
16+ /// Will return `Err` if an IO error occurs.
17+ fn into_inner_if ( self , pred : impl Fn ( & [ u8 ] ) -> bool ) -> crate :: Result < Option < KvPair > > ;
18+
919 /// Accesses the key-value pair.
1020 ///
1121 /// # Errors
Original file line number Diff line number Diff line change @@ -36,6 +36,16 @@ use crate::metrics::Metrics;
3636pub struct Guard ( crate :: Result < ( UserKey , UserValue ) > ) ;
3737
3838impl IterGuard for Guard {
39+ fn into_inner_if ( self , pred : impl Fn ( & [ u8 ] ) -> bool ) -> crate :: Result < Option < KvPair > > {
40+ let ( k, v) = self . 0 ?;
41+
42+ if pred ( & k) {
43+ Ok ( Some ( ( k, v) ) )
44+ } else {
45+ Ok ( None )
46+ }
47+ }
48+
3949 fn key ( self ) -> crate :: Result < UserKey > {
4050 self . 0 . map ( |( k, _) | k)
4151 }
You can’t perform that action at this time.
0 commit comments