Repository: cberner/redb
Pull request #105 (2021-12-29 04:07:34)

Fix get_range_reversed() to return public types


Patch:
diff --git a/src/table.rs b/src/table.rs
index 8e74d05..1c1b133 100644
--- a/src/table.rs
+++ b/src/table.rs
@@ -126,9 +126,10 @@ impl<'s, K: RedbKey + ?Sized, V: RedbValue + ?Sized> ReadOnlyTable<'s, K, V> {
     pub fn get_range_reversed<'a, T: RangeBounds<KR> + 'a, KR: AsRef<K>>(
         &'a self,
         range: T,
-    ) -> Result<BtreeRangeIter<T, KR, K, V>, Error> {
+    ) -> Result<RangeIter<T, KR, K, V>, Error> {
         self.storage
             .get_range_reversed(self.table_id, range, self.root_page)
+            .map(RangeIter::new)
     }
 
     pub fn len(&self) -> Result<usize, Error> {
@@ -186,7 +187,6 @@ impl<
 
 #[cfg(test)]
 mod test {
-    use crate::tree_store::BtreeEntry;
     use crate::types::{
         AsBytesWithLifetime, RedbKey, RedbValue, RefAsBytesLifetime, RefLifetime, WithLifetime,
     };
@@ -326,33 +326,6 @@ mod test {
         assert_eq!(value, table.get(b"hello").unwrap().unwrap().as_ref());
     }
 
-    #[test]
-    fn range_query_reversed() {
-        let tmpfile: NamedTempFile = NamedTempFile::new().unwrap();
-        let db = unsafe { Database::open(tmpfile.path(), 1024 * 1024).unwrap() };
-        let write_txn = db.begin_write().unwrap();
-        let mut table: Table<[u8], [u8]> = write_txn.open_table(b"x").unwrap();
-        for i in 0..10u8 {
-            let key = vec![i];
-            table.insert(&key, b"value").unwrap();
-        }
-        write_txn.commit().unwrap();
-
-        let read_txn = db.begin_read().unwrap();
-        let table: ReadOnlyTable<[u8], [u8]> = read_txn.open_table(b"x").unwrap();
-        let start = vec![3u8];
-        let end = vec![7u8];
-        let mut iter = table
-            .get_range_reversed(start.as_slice()..end.as_slice())
-            .unwrap();
-        for i in (3..7u8).rev() {
-            let entry = iter.next().unwrap();
-            assert_eq!(&[i], entry.key());
-            assert_eq!(b"value", entry.value());
-        }
-        assert!(iter.next().is_none());
-    }
-
     #[test]
     fn custom_ordering() {
         struct ReverseKey(Vec<u8>);


Test patch:
diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs
index c89fc48..3df7d02 100644
--- a/tests/integration_tests.rs
+++ b/tests/integration_tests.rs
@@ -278,3 +278,30 @@ fn range_query() {
     }
     assert!(iter.next().is_none());
 }
+
+#[test]
+fn range_query_reversed() {
+    let tmpfile: NamedTempFile = NamedTempFile::new().unwrap();
+    let db = unsafe { Database::open(tmpfile.path(), 1024 * 1024).unwrap() };
+    let write_txn = db.begin_write().unwrap();
+    let mut table: Table<[u8], [u8]> = write_txn.open_table(b"x").unwrap();
+    for i in 0..10u8 {
+        let key = vec![i];
+        table.insert(&key, b"value").unwrap();
+    }
+    write_txn.commit().unwrap();
+
+    let read_txn = db.begin_read().unwrap();
+    let table: ReadOnlyTable<[u8], [u8]> = read_txn.open_table(b"x").unwrap();
+    let start = vec![3u8];
+    let end = vec![7u8];
+    let mut iter = table
+        .get_range_reversed(start.as_slice()..end.as_slice())
+        .unwrap();
+    for i in (3..7u8).rev() {
+        let (key, value) = iter.next().unwrap();
+        assert_eq!(&[i], key);
+        assert_eq!(b"value", value);
+    }
+    assert!(iter.next().is_none());
+}