Skip to content

Commit

Permalink
Make ReadOnlyTable::get() return a 'static lifetime
Browse files Browse the repository at this point in the history
  • Loading branch information
cberner committed Mar 22, 2024
1 parent 7377b3b commit 30d6cc9
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ backwards compatible with 1.x. To upgrade, consider using a pattern like that in
* Add `retain()` and `retain_in()` to `Table`
* Add `extract_if()` and `extract_from_if()` to `Table`
* Add `range()` returning a `Range` with the `'static` lifetime to read-only tables
* Add `get()` returning a range with the `'static` lifetime to read-only multimap tables
* Add `get()` returning a range with the `'static` lifetime to read-only tables
* Add `close()` method to `ReadTransaction`

## 1.5.1 - 2024-03-16
Expand Down
3 changes: 1 addition & 2 deletions benches/common.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use redb::{AccessGuard, ReadableTable};
use redb::{ReadableTableMetadata, TableDefinition};
use redb::{AccessGuard, ReadableTableMetadata, TableDefinition};
use rocksdb::{Direction, IteratorMode, TransactionDB, TransactionOptions, WriteOptions};
use sanakirja::btree::page_unsized;
use sanakirja::{Commit, RootDb};
Expand Down
2 changes: 1 addition & 1 deletion examples/int_keys.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use redb::{Database, Error, ReadableTable, TableDefinition};
use redb::{Database, Error, TableDefinition};

const TABLE: TableDefinition<u64, u64> = TableDefinition::new("my_data");

Expand Down
7 changes: 7 additions & 0 deletions src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,13 @@ impl<K: Key + 'static, V: Value + 'static> ReadOnlyTable<K, V> {
})
}

pub fn get<'a>(
&self,
key: impl Borrow<K::SelfType<'a>>,
) -> Result<Option<AccessGuard<'static, V>>> {
self.tree.get(key.borrow())
}

/// This method is like [`ReadableTable::range()`], but the iterator is reference counted and keeps the transaction
/// alive until it is dropped.
pub fn range<'a, KR>(&self, range: impl RangeBounds<KR>) -> Result<Range<'static, K, V>>
Expand Down
2 changes: 1 addition & 1 deletion tests/backward_compatibility.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use redb::{DatabaseError, ReadableTable, ReadableTableMetadata};
use redb::{DatabaseError, ReadableTableMetadata};
use redb1::ReadableTable as ReadableTable1;

const ELEMENTS: usize = 3;
Expand Down

0 comments on commit 30d6cc9

Please sign in to comment.