Skip to content

Commit

Permalink
Remove T on cursors
Browse files Browse the repository at this point in the history
  • Loading branch information
dureuill authored and Kerollmops committed Mar 4, 2025
1 parent 88c1a2d commit 92a9f13
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 122 deletions.
14 changes: 7 additions & 7 deletions heed/src/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ use crate::mdb::error::mdb_result;
use crate::mdb::ffi;
use crate::*;

pub struct RoCursor<'txn, T> {
pub struct RoCursor<'txn> {
cursor: *mut ffi::MDB_cursor,
_marker: marker::PhantomData<&'txn T>,
_marker: marker::PhantomData<&'txn ()>,
}

impl<'txn, T> RoCursor<'txn, T> {
impl<'txn> RoCursor<'txn> {
// TODO should I ask for a &mut RoTxn<'_, T>, here?
pub(crate) fn new(txn: &'txn RoTxn<'_, T>, dbi: ffi::MDB_dbi) -> Result<RoCursor<'txn, T>> {
pub(crate) fn new<T>(txn: &'txn RoTxn<'_, T>, dbi: ffi::MDB_dbi) -> Result<RoCursor<'txn>> {
let mut cursor: *mut ffi::MDB_cursor = ptr::null_mut();
let mut txn = txn.txn_ptr();
unsafe { mdb_result(ffi::mdb_cursor_open(txn.as_mut(), dbi, &mut cursor))? }
Expand Down Expand Up @@ -237,14 +237,14 @@ impl<'txn, T> RoCursor<'txn, T> {
}
}

impl<T> Drop for RoCursor<'_, T> {
impl Drop for RoCursor<'_> {
fn drop(&mut self) {
unsafe { ffi::mdb_cursor_close(self.cursor) }
}
}

pub struct RwCursor<'txn> {
cursor: RoCursor<'txn, WithoutTls>,
cursor: RoCursor<'txn>,
}

impl<'txn> RwCursor<'txn> {
Expand Down Expand Up @@ -404,7 +404,7 @@ impl<'txn> RwCursor<'txn> {
}

impl<'txn> Deref for RwCursor<'txn> {
type Target = RoCursor<'txn, WithoutTls>;
type Target = RoCursor<'txn>;

fn deref(&self) -> &Self::Target {
&self.cursor
Expand Down
18 changes: 9 additions & 9 deletions heed/src/databases/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,13 @@ impl<'e, 'n, T, KC, DC, C> DatabaseOpenOptions<'e, 'n, T, KC, DC, C> {
}
}

impl<T, KC, DC, C> Clone for DatabaseOpenOptions<'_, '_, T, KC, DC, C> {
impl<KC, DC, C> Clone for DatabaseOpenOptions<'_, '_, KC, DC, C> {
fn clone(&self) -> Self {
*self
}
}

impl<T, KC, DC, C> Copy for DatabaseOpenOptions<'_, '_, T, KC, DC, C> {}
impl<KC, DC, C> Copy for DatabaseOpenOptions<'_, '_, KC, DC, C> {}

/// A typed database that accepts only the types it was created with.
///
Expand Down Expand Up @@ -433,7 +433,7 @@ impl<KC, DC, C> Database<KC, DC, C> {
&self,
txn: &'txn RoTxn<T>,
key: &'a KC::EItem,
) -> Result<Option<RoIter<'txn, T, KC, DC, MoveOnCurrentKeyDuplicates>>>
) -> Result<Option<RoIter<'txn, KC, DC, MoveOnCurrentKeyDuplicates>>>
where
KC: BytesEncode<'a>,
{
Expand Down Expand Up @@ -1026,7 +1026,7 @@ impl<KC, DC, C> Database<KC, DC, C> {
/// wtxn.commit()?;
/// # Ok(()) }
/// ```
pub fn iter<'txn, T>(&self, txn: &'txn RoTxn<T>) -> Result<RoIter<'txn, T, KC, DC>> {
pub fn iter<'txn, T>(&self, txn: &'txn RoTxn<T>) -> Result<RoIter<'txn, KC, DC>> {
assert_eq_env_db_txn!(self, txn);
RoCursor::new(txn, self.dbi).map(|cursor| RoIter::new(cursor))
}
Expand Down Expand Up @@ -1128,7 +1128,7 @@ impl<KC, DC, C> Database<KC, DC, C> {
/// wtxn.commit()?;
/// # Ok(()) }
/// ```
pub fn rev_iter<'txn, T>(&self, txn: &'txn RoTxn<T>) -> Result<RoRevIter<'txn, T, KC, DC>> {
pub fn rev_iter<'txn, T>(&self, txn: &'txn RoTxn<T>) -> Result<RoRevIter<'txn, KC, DC>> {
assert_eq_env_db_txn!(self, txn);

RoCursor::new(txn, self.dbi).map(|cursor| RoRevIter::new(cursor))
Expand Down Expand Up @@ -1239,7 +1239,7 @@ impl<KC, DC, C> Database<KC, DC, C> {
&self,
txn: &'txn RoTxn<T>,
range: &'a R,
) -> Result<RoRange<'txn, T, KC, DC, C>>
) -> Result<RoRange<'txn, KC, DC, C>>
where
KC: BytesEncode<'a>,
R: RangeBounds<KC::EItem>,
Expand Down Expand Up @@ -1412,7 +1412,7 @@ impl<KC, DC, C> Database<KC, DC, C> {
&self,
txn: &'txn RoTxn<T>,
range: &'a R,
) -> Result<RoRevRange<'txn, T, KC, DC, C>>
) -> Result<RoRevRange<'txn, KC, DC, C>>
where
KC: BytesEncode<'a>,
R: RangeBounds<KC::EItem>,
Expand Down Expand Up @@ -1587,7 +1587,7 @@ impl<KC, DC, C> Database<KC, DC, C> {
&self,
txn: &'txn RoTxn<T>,
prefix: &'a KC::EItem,
) -> Result<RoPrefix<'txn, T, KC, DC, C>>
) -> Result<RoPrefix<'txn, KC, DC, C>>
where
KC: BytesEncode<'a>,
C: LexicographicComparator,
Expand Down Expand Up @@ -1720,7 +1720,7 @@ impl<KC, DC, C> Database<KC, DC, C> {
&self,
txn: &'txn RoTxn<'_, T>,
prefix: &'a KC::EItem,
) -> Result<RoRevPrefix<'txn, T, KC, DC, C>>
) -> Result<RoRevPrefix<'txn, KC, DC, C>>
where
KC: BytesEncode<'a>,
C: LexicographicComparator,
Expand Down
26 changes: 13 additions & 13 deletions heed/src/databases/encrypted_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ use crate::*;
/// # Ok(()) }
/// ```
#[derive(Debug)]
pub struct EncryptedDatabaseOpenOptions<'e, 'n, T, KC, DC, C = DefaultComparator> {
inner: DatabaseOpenOptions<'e, 'n, T, KC, DC, C>,
pub struct EncryptedDatabaseOpenOptions<'e, 'n, KC, DC, C = DefaultComparator> {
inner: DatabaseOpenOptions<'e, 'n, KC, DC, C>,
}

impl<'e, T> EncryptedDatabaseOpenOptions<'e, 'static, T, Unspecified, Unspecified> {
Expand All @@ -64,7 +64,7 @@ impl<'e, T> EncryptedDatabaseOpenOptions<'e, 'static, T, Unspecified, Unspecifie
}
}

impl<'e, 'n, T, KC, DC, C> EncryptedDatabaseOpenOptions<'e, 'n, T, KC, DC, C> {
impl<'e, 'n, KC, DC, C> EncryptedDatabaseOpenOptions<'e, 'n, KC, DC, C> {
/// Change the type of the database.
///
/// The default types are [`Unspecified`] and require a call to [`Database::remap_types`]
Expand All @@ -75,7 +75,7 @@ impl<'e, 'n, T, KC, DC, C> EncryptedDatabaseOpenOptions<'e, 'n, T, KC, DC, C> {
/// Change the customized key compare function of the database.
///
/// By default no customized compare function will be set when opening a database.
pub fn key_comparator<NC>(self) -> EncryptedDatabaseOpenOptions<'e, 'n, T, KC, DC, NC> {
pub fn key_comparator<NC>(self) -> EncryptedDatabaseOpenOptions<'e, 'n, KC, DC, NC> {
EncryptedDatabaseOpenOptions { inner: self.inner.key_comparator() }
}

Expand Down Expand Up @@ -139,13 +139,13 @@ impl<'e, 'n, T, KC, DC, C> EncryptedDatabaseOpenOptions<'e, 'n, T, KC, DC, C> {
}
}

impl<T, KC, DC, C> Clone for EncryptedDatabaseOpenOptions<'_, '_, T, KC, DC, C> {
impl<KC, DC, C> Clone for EncryptedDatabaseOpenOptions<'_, '_, KC, DC, C> {
fn clone(&self) -> Self {
*self
}
}

impl<T, KC, DC, C> Copy for EncryptedDatabaseOpenOptions<'_, '_, T, KC, DC, C> {}
impl<KC, DC, C> Copy for EncryptedDatabaseOpenOptions<'_, '_, KC, DC, C> {}

/// A typed database that accepts only the types it was created with.
///
Expand Down Expand Up @@ -374,7 +374,7 @@ impl<KC, DC, C> EncryptedDatabase<KC, DC, C> {
&self,
txn: &'txn mut RoTxn<T>,
key: &'a KC::EItem,
) -> Result<Option<RoIter<'txn, T, KC, DC, MoveOnCurrentKeyDuplicates>>>
) -> Result<Option<RoIter<'txn, KC, DC, MoveOnCurrentKeyDuplicates>>>
where
KC: BytesEncode<'a>,
{
Expand Down Expand Up @@ -862,7 +862,7 @@ impl<KC, DC, C> EncryptedDatabase<KC, DC, C> {
/// wtxn.commit()?;
/// # Ok(()) }
/// ```
pub fn iter<'txn, T>(&self, txn: &'txn mut RoTxn<T>) -> Result<RoIter<'txn, T, KC, DC>> {
pub fn iter<'txn, T>(&self, txn: &'txn mut RoTxn<T>) -> Result<RoIter<'txn, KC, DC>> {
self.inner.iter(txn)
}

Expand Down Expand Up @@ -961,7 +961,7 @@ impl<KC, DC, C> EncryptedDatabase<KC, DC, C> {
/// wtxn.commit()?;
/// # Ok(()) }
/// ```
pub fn rev_iter<'txn, T>(&self, txn: &'txn mut RoTxn<T>) -> Result<RoRevIter<'txn, T, KC, DC>> {
pub fn rev_iter<'txn, T>(&self, txn: &'txn mut RoTxn<T>) -> Result<RoRevIter<'txn, KC, DC>> {
self.inner.rev_iter(txn)
}

Expand Down Expand Up @@ -1068,7 +1068,7 @@ impl<KC, DC, C> EncryptedDatabase<KC, DC, C> {
&self,
txn: &'txn mut RoTxn<T>,
range: &'a R,
) -> Result<RoRange<'txn, T, KC, DC, C>>
) -> Result<RoRange<'txn, KC, DC, C>>
where
KC: BytesEncode<'a>,
R: RangeBounds<KC::EItem>,
Expand Down Expand Up @@ -1191,7 +1191,7 @@ impl<KC, DC, C> EncryptedDatabase<KC, DC, C> {
&self,
txn: &'txn mut RoTxn<T>,
range: &'a R,
) -> Result<RoRevRange<'txn, T, KC, DC, C>>
) -> Result<RoRevRange<'txn, KC, DC, C>>
where
KC: BytesEncode<'a>,
R: RangeBounds<KC::EItem>,
Expand Down Expand Up @@ -1315,7 +1315,7 @@ impl<KC, DC, C> EncryptedDatabase<KC, DC, C> {
&self,
txn: &'txn mut RoTxn<T>,
prefix: &'a KC::EItem,
) -> Result<RoPrefix<'txn, T, KC, DC, C>>
) -> Result<RoPrefix<'txn, KC, DC, C>>
where
KC: BytesEncode<'a>,
C: LexicographicComparator,
Expand Down Expand Up @@ -1440,7 +1440,7 @@ impl<KC, DC, C> EncryptedDatabase<KC, DC, C> {
&self,
txn: &'txn mut RoTxn<T>,
prefix: &'a KC::EItem,
) -> Result<RoRevPrefix<'txn, T, KC, DC, C>>
) -> Result<RoRevPrefix<'txn, KC, DC, C>>
where
KC: BytesEncode<'a>,
C: LexicographicComparator,
Expand Down
Loading

0 comments on commit 92a9f13

Please sign in to comment.