@@ -23,36 +23,32 @@ impl<'a, K, V> ForwardInMemoryCursor<'a, K, V> {
2323 self . is_empty
2424 }
2525
26- /// Returns the last entry iterated to. Returns `None` if never iterated or if exhausted .
26+ /// Returns the current entry pointed to be the cursor, or `None` if no entries are left .
2727 #[ inline]
28- pub fn current ( & self ) -> Option < & ' a ( K , V ) > {
28+ pub fn current ( & self ) -> Option < & ( K , V ) > {
2929 self . entries . clone ( ) . next ( )
3030 }
31- }
32-
33- impl < ' a , K , V > Iterator for ForwardInMemoryCursor < ' a , K , V > {
34- type Item = & ' a ( K , V ) ;
3531
36- fn next ( & mut self ) -> Option < & ' a ( K , V ) > {
37- self . entries . next ( ) ;
38- self . current ( )
32+ # [ inline ]
33+ fn next ( & mut self ) -> Option < & ( K , V ) > {
34+ self . entries . next ( )
3935 }
4036}
4137
42- impl < ' a , K , V > ForwardInMemoryCursor < ' a , K , V >
38+ impl < K , V > ForwardInMemoryCursor < ' _ , K , V >
4339where
4440 K : PartialOrd + Clone ,
4541 V : Clone ,
4642{
4743 /// Returns the first entry from the current cursor position that's greater or equal to the
4844 /// provided key. This method advances the cursor forward.
49- pub fn seek ( & mut self , key : & K ) -> Option < & ' a ( K , V ) > {
45+ pub fn seek ( & mut self , key : & K ) -> Option < ( K , V ) > {
5046 self . advance_while ( |k| k < key)
5147 }
5248
5349 /// Returns the first entry from the current cursor position that's greater than the provided
5450 /// key. This method advances the cursor forward.
55- pub fn first_after ( & mut self , key : & K ) -> Option < & ' a ( K , V ) > {
51+ pub fn first_after ( & mut self , key : & K ) -> Option < ( K , V ) > {
5652 self . advance_while ( |k| k <= key)
5753 }
5854
@@ -61,15 +57,17 @@ where
6157 ///
6258 /// Returns the first entry for which `predicate` returns `false` or `None`. The cursor will
6359 /// point to the returned entry.
64- fn advance_while ( & mut self , predicate : impl Fn ( & ' a K ) -> bool ) -> Option < & ' a ( K , V ) > {
60+ fn advance_while ( & mut self , predicate : impl Fn ( & K ) -> bool ) -> Option < ( K , V ) > {
61+ let mut entry;
6562 loop {
66- if self . current ( ) . is_some_and ( |( k, _) | predicate ( k) ) {
67- self . entries . next ( ) ;
63+ entry = self . current ( ) ;
64+ if entry. is_some_and ( |( k, _) | predicate ( k) ) {
65+ self . next ( ) ;
6866 } else {
6967 break ;
7068 }
7169 }
72- self . current ( )
70+ entry . cloned ( )
7371 }
7472}
7573
@@ -80,17 +78,18 @@ mod tests {
8078 #[ test]
8179 fn test_cursor ( ) {
8280 let mut cursor = ForwardInMemoryCursor :: new ( & [ ( 1 , ( ) ) , ( 2 , ( ) ) , ( 3 , ( ) ) , ( 4 , ( ) ) , ( 5 , ( ) ) ] ) ;
81+ assert_eq ! ( cursor. current( ) , Some ( & ( 1 , ( ) ) ) ) ;
8382
84- assert_eq ! ( cursor. seek( & 0 ) , Some ( & ( 1 , ( ) ) ) ) ;
83+ assert_eq ! ( cursor. seek( & 0 ) , Some ( ( 1 , ( ) ) ) ) ;
8584 assert_eq ! ( cursor. current( ) , Some ( & ( 1 , ( ) ) ) ) ;
8685
87- assert_eq ! ( cursor. seek( & 3 ) , Some ( & ( 3 , ( ) ) ) ) ;
86+ assert_eq ! ( cursor. seek( & 3 ) , Some ( ( 3 , ( ) ) ) ) ;
8887 assert_eq ! ( cursor. current( ) , Some ( & ( 3 , ( ) ) ) ) ;
8988
90- assert_eq ! ( cursor. seek( & 3 ) , Some ( & ( 3 , ( ) ) ) ) ;
89+ assert_eq ! ( cursor. seek( & 3 ) , Some ( ( 3 , ( ) ) ) ) ;
9190 assert_eq ! ( cursor. current( ) , Some ( & ( 3 , ( ) ) ) ) ;
9291
93- assert_eq ! ( cursor. seek( & 4 ) , Some ( & ( 4 , ( ) ) ) ) ;
92+ assert_eq ! ( cursor. seek( & 4 ) , Some ( ( 4 , ( ) ) ) ) ;
9493 assert_eq ! ( cursor. current( ) , Some ( & ( 4 , ( ) ) ) ) ;
9594
9695 assert_eq ! ( cursor. seek( & 6 ) , None ) ;
0 commit comments