From 335e5031d24b0bf34a9973200f507ecc876d02cb Mon Sep 17 00:00:00 2001 From: Christopher Berner Date: Sat, 3 Feb 2024 10:05:42 -0800 Subject: [PATCH] Remove lifetimes from read-only tables --- benches/common.rs | 8 ++++---- src/multimap_table.rs | 20 ++++++++------------ src/table.rs | 22 ++++++++-------------- src/transactions.rs | 8 ++++---- 4 files changed, 24 insertions(+), 34 deletions(-) diff --git a/benches/common.rs b/benches/common.rs index d4147ffb..67c33e00 100644 --- a/benches/common.rs +++ b/benches/common.rs @@ -108,7 +108,7 @@ pub struct RedbBenchReadTransaction { } impl BenchReadTransaction for RedbBenchReadTransaction { - type T<'txn> = RedbBenchReader<'txn> where Self: 'txn; + type T<'txn> = RedbBenchReader where Self: 'txn; fn get_reader(&self) -> Self::T<'_> { let table = self.txn.open_table(X).unwrap(); @@ -116,11 +116,11 @@ impl BenchReadTransaction for RedbBenchReadTransaction { } } -pub struct RedbBenchReader<'txn> { - table: redb::ReadOnlyTable<'txn, &'static [u8], &'static [u8]>, +pub struct RedbBenchReader { + table: redb::ReadOnlyTable<&'static [u8], &'static [u8]>, } -impl<'txn> BenchReader for RedbBenchReader<'txn> { +impl BenchReader for RedbBenchReader { type Output<'out> = RedbAccessGuard<'out> where Self: 'out; type Iterator<'out> = RedbBenchIterator<'out> where Self: 'out; diff --git a/src/multimap_table.rs b/src/multimap_table.rs index fca55ed0..61bd53f9 100644 --- a/src/multimap_table.rs +++ b/src/multimap_table.rs @@ -1219,15 +1219,14 @@ pub trait ReadableMultimapTable: Sea } /// A read-only untyped multimap table -pub struct ReadOnlyUntypedMultimapTable<'txn> { +pub struct ReadOnlyUntypedMultimapTable { tree: RawBtree, fixed_key_size: Option, fixed_value_size: Option, mem: Arc, - _lifetime: PhantomData<&'txn ()>, } -impl<'txn> ReadOnlyUntypedMultimapTable<'txn> { +impl ReadOnlyUntypedMultimapTable { pub(crate) fn new( root_page: Option<(PageNumber, Checksum)>, fixed_key_size: Option, @@ -1244,7 +1243,6 @@ impl<'txn> ReadOnlyUntypedMultimapTable<'txn> { fixed_key_size, fixed_value_size, mem, - _lifetime: Default::default(), } } @@ -1269,27 +1267,25 @@ impl<'txn> ReadOnlyUntypedMultimapTable<'txn> { } /// A read-only multimap table -pub struct ReadOnlyMultimapTable<'txn, K: RedbKey + 'static, V: RedbKey + 'static> { +pub struct ReadOnlyMultimapTable { tree: Btree>, mem: Arc, transaction_guard: Arc, _value_type: PhantomData, - _lifetime: PhantomData<&'txn ()>, } -impl<'txn, K: RedbKey + 'static, V: RedbKey + 'static> ReadOnlyMultimapTable<'txn, K, V> { +impl ReadOnlyMultimapTable { pub(crate) fn new( root_page: Option<(PageNumber, Checksum)>, hint: PageHint, guard: Arc, mem: Arc, - ) -> Result> { + ) -> Result> { Ok(ReadOnlyMultimapTable { tree: Btree::new(root_page, hint, guard.clone(), mem.clone())?, mem, transaction_guard: guard, _value_type: Default::default(), - _lifetime: Default::default(), }) } @@ -1323,8 +1319,8 @@ impl<'txn, K: RedbKey + 'static, V: RedbKey + 'static> ReadOnlyMultimapTable<'tx } } -impl<'txn, K: RedbKey + 'static, V: RedbKey + 'static> ReadableMultimapTable - for ReadOnlyMultimapTable<'txn, K, V> +impl ReadableMultimapTable + for ReadOnlyMultimapTable { /// Returns an iterator over all values for the given key. Values are in ascending order. fn get<'a>(&self, key: impl Borrow>) -> Result> @@ -1391,4 +1387,4 @@ impl<'txn, K: RedbKey + 'static, V: RedbKey + 'static> ReadableMultimapTable Sealed for ReadOnlyMultimapTable<'_, K, V> {} +impl Sealed for ReadOnlyMultimapTable {} diff --git a/src/table.rs b/src/table.rs index bf7e2134..329a34af 100644 --- a/src/table.rs +++ b/src/table.rs @@ -381,12 +381,11 @@ pub trait ReadableTable: Sealed { } /// A read-only untyped table -pub struct ReadOnlyUntypedTable<'txn> { +pub struct ReadOnlyUntypedTable { tree: RawBtree, - _lifetime: PhantomData<&'txn ()>, } -impl<'txn> ReadOnlyUntypedTable<'txn> { +impl ReadOnlyUntypedTable { pub(crate) fn new( root_page: Option<(PageNumber, Checksum)>, fixed_key_size: Option, @@ -395,7 +394,6 @@ impl<'txn> ReadOnlyUntypedTable<'txn> { ) -> Self { Self { tree: RawBtree::new(root_page, fixed_key_size, fixed_value_size, mem), - _lifetime: Default::default(), } } @@ -415,26 +413,24 @@ impl<'txn> ReadOnlyUntypedTable<'txn> { } /// A read-only table -pub struct ReadOnlyTable<'txn, K: RedbKey + 'static, V: RedbValue + 'static> { +pub struct ReadOnlyTable { name: String, tree: Btree, transaction_guard: Arc, - _lifetime: PhantomData<&'txn ()>, } -impl<'txn, K: RedbKey + 'static, V: RedbValue + 'static> ReadOnlyTable<'txn, K, V> { +impl ReadOnlyTable { pub(crate) fn new( name: String, root_page: Option<(PageNumber, Checksum)>, hint: PageHint, guard: Arc, mem: Arc, - ) -> Result> { + ) -> Result> { Ok(ReadOnlyTable { name, tree: Btree::new(root_page, hint, guard.clone(), mem)?, transaction_guard: guard, - _lifetime: Default::default(), }) } @@ -450,9 +446,7 @@ impl<'txn, K: RedbKey + 'static, V: RedbValue + 'static> ReadOnlyTable<'txn, K, } } -impl<'txn, K: RedbKey + 'static, V: RedbValue + 'static> ReadableTable - for ReadOnlyTable<'txn, K, V> -{ +impl ReadableTable for ReadOnlyTable { fn get<'a>(&self, key: impl Borrow>) -> Result>> where K: 'a, @@ -492,9 +486,9 @@ impl<'txn, K: RedbKey + 'static, V: RedbValue + 'static> ReadableTable } } -impl Sealed for ReadOnlyTable<'_, K, V> {} +impl Sealed for ReadOnlyTable {} -impl Debug for ReadOnlyTable<'_, K, V> { +impl Debug for ReadOnlyTable { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { debug_helper(f, &self.name, self.len(), self.first(), self.last()) } diff --git a/src/transactions.rs b/src/transactions.rs index 092cd508..2657fd2c 100644 --- a/src/transactions.rs +++ b/src/transactions.rs @@ -1205,7 +1205,7 @@ impl ReadTransaction { pub fn open_table( &self, definition: TableDefinition, - ) -> Result, TableError> { + ) -> Result, TableError> { let header = self .tree .get_table::(definition.name(), TableType::Normal)? @@ -1224,7 +1224,7 @@ impl ReadTransaction { pub fn open_untyped_table( &self, handle: impl TableHandle, - ) -> Result, TableError> { + ) -> Result { let header = self .tree .get_table_untyped(handle.name(), TableType::Normal)? @@ -1242,7 +1242,7 @@ impl ReadTransaction { pub fn open_multimap_table( &self, definition: MultimapTableDefinition, - ) -> Result, TableError> { + ) -> Result, TableError> { let header = self .tree .get_table::(definition.name(), TableType::Multimap)? @@ -1260,7 +1260,7 @@ impl ReadTransaction { pub fn open_untyped_multimap_table( &self, handle: impl MultimapTableHandle, - ) -> Result, TableError> { + ) -> Result { let header = self .tree .get_table_untyped(handle.name(), TableType::Multimap)?