Skip to content

Commit

Permalink
Remove a bunch of superfluous lifetime bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
cberner committed Mar 21, 2024
1 parent c3fbcea commit f4e9e09
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 46 deletions.
31 changes: 8 additions & 23 deletions src/multimap_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -987,11 +987,7 @@ impl<'txn, K: Key + 'static, V: Key + 'static> MultimapTable<'txn, K, V> {
&mut self,
key: impl Borrow<K::SelfType<'a>>,
value: impl Borrow<V::SelfType<'a>>,
) -> Result<bool>
where
K: 'a,
V: 'a,
{
) -> Result<bool> {
let get_result = self.tree.get(key.borrow())?;
if get_result.is_none() {
return Ok(false);
Expand Down Expand Up @@ -1119,10 +1115,10 @@ impl<'txn, K: Key + 'static, V: Key + 'static> MultimapTable<'txn, K, V> {
/// Removes all values for the given key
///
/// Returns an iterator over the removed values. Values are in ascending order.
pub fn remove_all<'a>(&mut self, key: impl Borrow<K::SelfType<'a>>) -> Result<MultimapValue<V>>
where
K: 'a,
{
pub fn remove_all<'a>(
&mut self,
key: impl Borrow<K::SelfType<'a>>,
) -> Result<MultimapValue<V>> {
let iter = if let Some(collection) = self.tree.remove(key.borrow())? {
let mut pages = vec![];
if matches!(
Expand Down Expand Up @@ -1191,10 +1187,7 @@ impl<'txn, K: Key + 'static, V: Key + 'static> ReadableMultimapTable<K, V>
for MultimapTable<'txn, K, V>
{
/// Returns an iterator over all values for the given key. Values are in ascending order.
fn get<'a>(&self, key: impl Borrow<K::SelfType<'a>>) -> Result<MultimapValue<V>>
where
K: 'a,
{
fn get<'a>(&self, key: impl Borrow<K::SelfType<'a>>) -> Result<MultimapValue<V>> {
let guard = self.transaction.transaction_guard();
let iter = if let Some(collection) = self.tree.get(key.borrow())? {
DynamicCollection::iter(collection, guard, self.mem.clone())?
Expand All @@ -1212,7 +1205,6 @@ impl<'txn, K: Key + 'static, V: Key + 'static> ReadableMultimapTable<K, V>
/// Returns a double-ended iterator over a range of elements in the table
fn range<'a, KR>(&self, range: impl RangeBounds<KR> + 'a) -> Result<MultimapRange<K, V>>
where
K: 'a,
KR: Borrow<K::SelfType<'a>> + 'a,
{
let inner = self.tree.range(&range)?;
Expand All @@ -1235,13 +1227,10 @@ impl<'txn, K: Key + 'static, V: Key + 'static> Drop for MultimapTable<'txn, K, V

pub trait ReadableMultimapTable<K: Key + 'static, V: Key + 'static>: ReadableTableMetadata {
/// Returns an iterator over all values for the given key. Values are in ascending order.
fn get<'a>(&self, key: impl Borrow<K::SelfType<'a>>) -> Result<MultimapValue<V>>
where
K: 'a;
fn get<'a>(&self, key: impl Borrow<K::SelfType<'a>>) -> Result<MultimapValue<V>>;

fn range<'a, KR>(&self, range: impl RangeBounds<KR> + 'a) -> Result<MultimapRange<K, V>>
where
K: 'a,
KR: Borrow<K::SelfType<'a>> + 'a;

/// Returns an double-ended iterator over all elements in the table. Values are in ascending
Expand Down Expand Up @@ -1395,10 +1384,7 @@ impl<K: Key + 'static, V: Key + 'static> ReadableMultimapTable<K, V>
for ReadOnlyMultimapTable<K, V>
{
/// Returns an iterator over all values for the given key. Values are in ascending order.
fn get<'a>(&self, key: impl Borrow<K::SelfType<'a>>) -> Result<MultimapValue<V>>
where
K: 'a,
{
fn get<'a>(&self, key: impl Borrow<K::SelfType<'a>>) -> Result<MultimapValue<V>> {
let iter = if let Some(collection) = self.tree.get(key.borrow())? {
DynamicCollection::iter(collection, self.transaction_guard.clone(), self.mem.clone())?
} else {
Expand All @@ -1414,7 +1400,6 @@ impl<K: Key + 'static, V: Key + 'static> ReadableMultimapTable<K, V>

fn range<'a, KR>(&self, range: impl RangeBounds<KR> + 'a) -> Result<MultimapRange<K, V>>
where
K: 'a,
KR: Borrow<K::SelfType<'a>> + 'a,
{
let inner = self.tree.range(&range)?;
Expand Down
28 changes: 5 additions & 23 deletions src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ impl<'txn, K: Key + 'static, V: Value + 'static> Table<'txn, K, V> {
predicate: F,
) -> Result<ExtractIf<'a, K, V, F>>
where
K: 'a0,
KR: Borrow<K::SelfType<'a0>> + 'a0,
{
self.tree
Expand Down Expand Up @@ -214,10 +213,7 @@ impl<'txn, K: Key + 'static, V: Value + 'static> Table<'txn, K, V> {
pub fn remove<'a>(
&mut self,
key: impl Borrow<K::SelfType<'a>>,
) -> Result<Option<AccessGuard<V>>>
where
K: 'a,
{
) -> Result<Option<AccessGuard<V>>> {
self.tree.remove(key.borrow())
}
}
Expand All @@ -229,10 +225,7 @@ impl<'txn, K: Key + 'static, V: MutInPlaceValue + 'static> Table<'txn, K, V> {
&mut self,
key: impl Borrow<K::SelfType<'a>>,
value_length: u32,
) -> Result<AccessGuardMut<V>>
where
K: 'a,
{
) -> Result<AccessGuardMut<V>> {
if value_length as usize > MAX_VALUE_LENGTH {
return Err(StorageError::ValueTooLarge(value_length as usize));
}
Expand Down Expand Up @@ -264,16 +257,12 @@ impl<'txn, K: Key + 'static, V: Value + 'static> ReadableTableMetadata for Table
}

impl<'txn, K: Key + 'static, V: Value + 'static> ReadableTable<K, V> for Table<'txn, K, V> {
fn get<'a>(&self, key: impl Borrow<K::SelfType<'a>>) -> Result<Option<AccessGuard<V>>>
where
K: 'a,
{
fn get<'a>(&self, key: impl Borrow<K::SelfType<'a>>) -> Result<Option<AccessGuard<V>>> {
self.tree.get(key.borrow())
}

fn range<'a, KR>(&self, range: impl RangeBounds<KR> + 'a) -> Result<Range<K, V>>
where
K: 'a,
KR: Borrow<K::SelfType<'a>> + 'a,
{
self.tree
Expand Down Expand Up @@ -358,9 +347,7 @@ pub trait ReadableTableMetadata: Sealed {

pub trait ReadableTable<K: Key + 'static, V: Value + 'static>: ReadableTableMetadata {
/// Returns the value corresponding to the given key
fn get<'a>(&self, key: impl Borrow<K::SelfType<'a>>) -> Result<Option<AccessGuard<V>>>
where
K: 'a;
fn get<'a>(&self, key: impl Borrow<K::SelfType<'a>>) -> Result<Option<AccessGuard<V>>>;

/// Returns a double-ended iterator over a range of elements in the table
///
Expand Down Expand Up @@ -396,7 +383,6 @@ pub trait ReadableTable<K: Key + 'static, V: Value + 'static>: ReadableTableMeta
/// ```
fn range<'a, KR>(&self, range: impl RangeBounds<KR> + 'a) -> Result<Range<K, V>>
where
K: 'a,
KR: Borrow<K::SelfType<'a>> + 'a;

/// Returns the first key-value pair in the table, if it exists
Expand Down Expand Up @@ -509,16 +495,12 @@ impl<K: Key + 'static, V: Value + 'static> ReadableTableMetadata for ReadOnlyTab
}

impl<K: Key + 'static, V: Value + 'static> ReadableTable<K, V> for ReadOnlyTable<K, V> {
fn get<'a>(&self, key: impl Borrow<K::SelfType<'a>>) -> Result<Option<AccessGuard<V>>>
where
K: 'a,
{
fn get<'a>(&self, key: impl Borrow<K::SelfType<'a>>) -> Result<Option<AccessGuard<V>>> {
self.tree.get(key.borrow())
}

fn range<'a, KR>(&self, range: impl RangeBounds<KR> + 'a) -> Result<Range<K, V>>
where
K: 'a,
KR: Borrow<K::SelfType<'a>> + 'a,
{
self.tree
Expand Down

0 comments on commit f4e9e09

Please sign in to comment.