Skip to content

Commit

Permalink
Fix most of the issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerollmops committed Dec 14, 2024
1 parent 07fa118 commit 59148e8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion heed/src/cookbook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@
//! }
//!
//! impl<'t> ImmutableMap<'t> {
//! fn from_db(rtxn: &'t RoTxn, db: Database<Str, Str>) -> heed::Result<Self> {
//! fn from_db<T>(rtxn: &'t RoTxn<T>, db: Database<Str, Str>) -> heed::Result<Self> {
//! let mut map = HashMap::new();
//! for result in db.iter(rtxn)? {
//! let (k, v) = result?;
Expand Down
4 changes: 2 additions & 2 deletions heed/src/databases/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,7 @@ impl<KC, DC, C> Database<KC, DC, C> {
/// wtxn.commit()?;
/// # Ok(()) }
/// ```
pub fn iter_mut<'txn, T>(&self, txn: &'txn mut RwTxn) -> Result<RwIter<'txn, KC, DC>> {
pub fn iter_mut<'txn>(&self, txn: &'txn mut RwTxn) -> Result<RwIter<'txn, KC, DC>> {
assert_eq_env_db_txn!(self, txn);

RwCursor::new(txn, self.dbi).map(|cursor| RwIter::new(cursor))
Expand Down Expand Up @@ -1182,7 +1182,7 @@ impl<KC, DC, C> Database<KC, DC, C> {
/// wtxn.commit()?;
/// # Ok(()) }
/// ```
pub fn rev_iter_mut<'txn, T>(&self, txn: &'txn mut RwTxn) -> Result<RwRevIter<'txn, KC, DC>> {
pub fn rev_iter_mut<'txn>(&self, txn: &'txn mut RwTxn) -> Result<RwRevIter<'txn, KC, DC>> {
assert_eq_env_db_txn!(self, txn);

RwCursor::new(txn, self.dbi).map(|cursor| RwRevIter::new(cursor))
Expand Down
6 changes: 5 additions & 1 deletion heed/src/envs/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::mdb::lmdb_flags::AllDatabaseFlags;
use crate::EnvOpenOptions;
use crate::{
CompactionOption, Database, DatabaseOpenOptions, EnvFlags, Error, Result, RoTxn, RwTxn,
Unspecified,
Unspecified, WithoutTls,
};

/// An environment handle constructed by using [`EnvOpenOptions::open`].
Expand All @@ -43,6 +43,10 @@ impl<T> Env<T> {
self.inner.env_ptr
}

pub(crate) unsafe fn as_without_tls(&self) -> &Env<WithoutTls> {
unsafe { std::mem::transmute::<&Env<T>, &Env<WithoutTls>>(self) }
}

/// The size of the data file on disk.
///
/// # Example
Expand Down
18 changes: 11 additions & 7 deletions heed/src/txn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ use crate::Result;
/// ```rust
/// #[allow(dead_code)]
/// trait CovariantMarker<'a>: 'static {
/// type T: 'a;
/// type R: 'a;
///
/// fn is_covariant(&'a self) -> &'a Self::T;
/// fn is_covariant(&'a self) -> &'a Self::R;
/// }
///
/// impl<'a> CovariantMarker<'a> for heed::RoTxn<'static> {
/// type T = heed::RoTxn<'a>;
/// impl<'a, T> CovariantMarker<'a> for heed::RoTxn<'static, T> {
/// type R = heed::RoTxn<'a, T>;
///
/// fn is_covariant(&'a self) -> &'a heed::RoTxn<'a> {
/// fn is_covariant(&'a self) -> &'a heed::RoTxn<'a, T> {
/// self
/// }
/// }
Expand Down Expand Up @@ -193,10 +193,12 @@ impl<'p> RwTxn<'p> {
))?
};

let env_without_tls = unsafe { env.as_without_tls() };

Ok(RwTxn {
txn: RoTxn {
txn: NonNull::new(txn),
env: Cow::Borrowed(env),
env: Cow::Borrowed(env_without_tls),
_tls_marker: PhantomData,
},
})
Expand All @@ -210,10 +212,12 @@ impl<'p> RwTxn<'p> {
mdb_result(ffi::mdb_txn_begin(env.env_mut_ptr().as_mut(), parent_ptr, 0, &mut txn))?
};

let env_without_tls = unsafe { env.as_without_tls() };

Ok(RwTxn {
txn: RoTxn {
txn: NonNull::new(txn),
env: Cow::Borrowed(env),
env: Cow::Borrowed(env_without_tls),
_tls_marker: PhantomData,
},
})
Expand Down

0 comments on commit 59148e8

Please sign in to comment.