diff --git a/heed/src/databases/database.rs b/heed/src/databases/database.rs index de9b31df..e17a02b6 100644 --- a/heed/src/databases/database.rs +++ b/heed/src/databases/database.rs @@ -172,13 +172,13 @@ impl<'e, 'n, T, KC, DC, C> DatabaseOpenOptions<'e, 'n, T, KC, DC, C> { } } -impl Clone for DatabaseOpenOptions<'_, '_, KC, DC, C> { +impl Clone for DatabaseOpenOptions<'_, '_, T, KC, DC, C> { fn clone(&self) -> Self { *self } } -impl Copy for DatabaseOpenOptions<'_, '_, KC, DC, C> {} +impl Copy for DatabaseOpenOptions<'_, '_, T, KC, DC, C> {} /// A typed database that accepts only the types it was created with. /// diff --git a/heed/src/databases/encrypted_database.rs b/heed/src/databases/encrypted_database.rs index 0c19b655..4e06cbc1 100644 --- a/heed/src/databases/encrypted_database.rs +++ b/heed/src/databases/encrypted_database.rs @@ -53,29 +53,29 @@ use crate::*; /// # Ok(()) } /// ``` #[derive(Debug)] -pub struct EncryptedDatabaseOpenOptions<'e, 'n, KC, DC, C = DefaultComparator> { - inner: DatabaseOpenOptions<'e, 'n, KC, DC, C>, +pub struct EncryptedDatabaseOpenOptions<'e, 'n, T, KC, DC, C = DefaultComparator> { + inner: DatabaseOpenOptions<'e, 'n, T, KC, DC, C>, } -impl<'e> EncryptedDatabaseOpenOptions<'e, 'static, Unspecified, Unspecified> { +impl<'e, T> EncryptedDatabaseOpenOptions<'e, 'static, T, Unspecified, Unspecified> { /// Create an options struct to open/create a database with specific flags. - pub fn new(env: &'e EncryptedEnv) -> Self { + pub fn new(env: &'e EncryptedEnv) -> Self { EncryptedDatabaseOpenOptions { inner: DatabaseOpenOptions::new(&env.inner) } } } -impl<'e, 'n, KC, DC, C> EncryptedDatabaseOpenOptions<'e, 'n, KC, DC, C> { +impl<'e, 'n, T, KC, DC, C> EncryptedDatabaseOpenOptions<'e, 'n, T, KC, DC, C> { /// Change the type of the database. /// /// The default types are [`Unspecified`] and require a call to [`Database::remap_types`] /// to use the [`Database`]. - pub fn types(self) -> EncryptedDatabaseOpenOptions<'e, 'n, NKC, NDC> { + pub fn types(self) -> EncryptedDatabaseOpenOptions<'e, 'n, T, NKC, NDC> { EncryptedDatabaseOpenOptions { inner: self.inner.types() } } /// 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(self) -> EncryptedDatabaseOpenOptions<'e, 'n, KC, DC, NC> { + pub fn key_comparator(self) -> EncryptedDatabaseOpenOptions<'e, 'n, T, KC, DC, NC> { EncryptedDatabaseOpenOptions { inner: self.inner.key_comparator() } } @@ -111,7 +111,7 @@ impl<'e, 'n, KC, DC, C> EncryptedDatabaseOpenOptions<'e, 'n, KC, DC, C> { /// /// If not done, you might raise `Io(Os { code: 22, kind: InvalidInput, message: "Invalid argument" })` /// known as `EINVAL`. - pub fn open(&self, rtxn: &RoTxn) -> Result>> + pub fn open(&self, rtxn: &RoTxn) -> Result>> where KC: 'static, DC: 'static, @@ -139,13 +139,13 @@ impl<'e, 'n, KC, DC, C> EncryptedDatabaseOpenOptions<'e, 'n, KC, DC, C> { } } -impl Clone for EncryptedDatabaseOpenOptions<'_, '_, KC, DC, C> { +impl Clone for EncryptedDatabaseOpenOptions<'_, '_, T, KC, DC, C> { fn clone(&self) -> Self { *self } } -impl Copy for EncryptedDatabaseOpenOptions<'_, '_, KC, DC, C> {} +impl Copy for EncryptedDatabaseOpenOptions<'_, '_, T, KC, DC, C> {} /// A typed database that accepts only the types it was created with. /// @@ -305,9 +305,9 @@ impl EncryptedDatabase { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn get<'a, 'txn>( + pub fn get<'a, 'txn, T>( &self, - txn: &'txn mut RoTxn, + txn: &'txn mut RoTxn, key: &'a KC::EItem, ) -> Result> where @@ -369,11 +369,11 @@ impl EncryptedDatabase { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn get_duplicates<'a, 'txn>( + pub fn get_duplicates<'a, 'txn, T>( &self, - txn: &'txn mut RoTxn, + txn: &'txn mut RoTxn, key: &'a KC::EItem, - ) -> Result>> + ) -> Result>> where KC: BytesEncode<'a>, { @@ -424,9 +424,9 @@ impl EncryptedDatabase { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn get_lower_than<'a, 'txn>( + pub fn get_lower_than<'a, 'txn, T>( &self, - txn: &'txn mut RoTxn, + txn: &'txn mut RoTxn, key: &'a KC::EItem, ) -> Result> where @@ -480,9 +480,9 @@ impl EncryptedDatabase { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn get_lower_than_or_equal_to<'a, 'txn>( + pub fn get_lower_than_or_equal_to<'a, 'txn, T>( &self, - txn: &'txn mut RoTxn, + txn: &'txn mut RoTxn, key: &'a KC::EItem, ) -> Result> where @@ -536,9 +536,9 @@ impl EncryptedDatabase { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn get_greater_than<'a, 'txn>( + pub fn get_greater_than<'a, 'txn, T>( &self, - txn: &'txn mut RoTxn, + txn: &'txn mut RoTxn, key: &'a KC::EItem, ) -> Result> where @@ -592,9 +592,9 @@ impl EncryptedDatabase { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn get_greater_than_or_equal_to<'a, 'txn>( + pub fn get_greater_than_or_equal_to<'a, 'txn, T>( &self, - txn: &'txn mut RoTxn, + txn: &'txn mut RoTxn, key: &'a KC::EItem, ) -> Result> where @@ -640,7 +640,7 @@ impl EncryptedDatabase { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn first<'txn>(&self, txn: &'txn mut RoTxn) -> Result> + pub fn first<'txn, T>(&self, txn: &'txn mut RoTxn) -> Result> where KC: BytesDecode<'txn>, DC: BytesDecode<'txn>, @@ -684,7 +684,7 @@ impl EncryptedDatabase { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn last<'txn>(&self, txn: &'txn mut RoTxn) -> Result> + pub fn last<'txn, T>(&self, txn: &'txn mut RoTxn) -> Result> where KC: BytesDecode<'txn>, DC: BytesDecode<'txn>, @@ -731,7 +731,7 @@ impl EncryptedDatabase { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn len(&self, txn: &RoTxn) -> Result { + pub fn len(&self, txn: &RoTxn) -> Result { self.inner.len(txn) } @@ -774,7 +774,7 @@ impl EncryptedDatabase { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn is_empty(&self, txn: &RoTxn) -> Result { + pub fn is_empty(&self, txn: &RoTxn) -> Result { self.inner.is_empty(txn) } @@ -816,7 +816,7 @@ impl EncryptedDatabase { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn stat(&self, txn: &RoTxn) -> Result { + pub fn stat(&self, txn: &RoTxn) -> Result { self.inner.stat(txn) } @@ -860,7 +860,7 @@ impl EncryptedDatabase { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn iter<'txn>(&self, txn: &'txn mut RoTxn) -> Result> { + pub fn iter<'txn, T>(&self, txn: &'txn mut RoTxn) -> Result> { self.inner.iter(txn) } @@ -914,7 +914,7 @@ impl EncryptedDatabase { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn iter_mut<'txn>(&self, txn: &'txn mut RwTxn) -> Result> { + pub fn iter_mut<'txn, T>(&self, txn: &'txn mut RwTxn) -> Result> { self.inner.iter_mut(txn) } @@ -958,7 +958,7 @@ impl EncryptedDatabase { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn rev_iter<'txn>(&self, txn: &'txn mut RoTxn) -> Result> { + pub fn rev_iter<'txn, T>(&self, txn: &'txn mut RoTxn) -> Result> { self.inner.rev_iter(txn) } @@ -1013,7 +1013,7 @@ impl EncryptedDatabase { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn rev_iter_mut<'txn>(&self, txn: &'txn mut RwTxn) -> Result> { + pub fn rev_iter_mut<'txn, T>(&self, txn: &'txn mut RwTxn) -> Result> { self.inner.rev_iter_mut(txn) } @@ -1060,11 +1060,11 @@ impl EncryptedDatabase { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn range<'a, 'txn, R>( + pub fn range<'a, 'txn, R, T>( &self, - txn: &'txn mut RoTxn, + txn: &'txn mut RoTxn, range: &'a R, - ) -> Result> + ) -> Result> where KC: BytesEncode<'a>, R: RangeBounds, @@ -1182,11 +1182,11 @@ impl EncryptedDatabase { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn rev_range<'a, 'txn, R>( + pub fn rev_range<'a, 'txn, R, T>( &self, - txn: &'txn mut RoTxn, + txn: &'txn mut RoTxn, range: &'a R, - ) -> Result> + ) -> Result> where KC: BytesEncode<'a>, R: RangeBounds, @@ -1305,11 +1305,11 @@ impl EncryptedDatabase { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn prefix_iter<'a, 'txn>( + pub fn prefix_iter<'a, 'txn, T>( &self, - txn: &'txn mut RoTxn, + txn: &'txn mut RoTxn, prefix: &'a KC::EItem, - ) -> Result> + ) -> Result> where KC: BytesEncode<'a>, C: LexicographicComparator, @@ -1372,7 +1372,7 @@ impl EncryptedDatabase { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn prefix_iter_mut<'a, 'txn>( + pub fn prefix_iter_mut<'a, 'txn, T>( &self, txn: &'txn mut RwTxn, prefix: &'a KC::EItem, @@ -1429,11 +1429,11 @@ impl EncryptedDatabase { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn rev_prefix_iter<'a, 'txn>( + pub fn rev_prefix_iter<'a, 'txn, T>( &self, - txn: &'txn mut RoTxn, + txn: &'txn mut RoTxn, prefix: &'a KC::EItem, - ) -> Result> + ) -> Result> where KC: BytesEncode<'a>, C: LexicographicComparator, @@ -1496,7 +1496,7 @@ impl EncryptedDatabase { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn rev_prefix_iter_mut<'a, 'txn>( + pub fn rev_prefix_iter_mut<'a, 'txn, T>( &self, txn: &'txn mut RwTxn, prefix: &'a KC::EItem, @@ -1707,7 +1707,7 @@ impl EncryptedDatabase { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn get_or_put<'a, 'txn>( + pub fn get_or_put<'a, 'txn, T>( &'txn self, txn: &mut RwTxn, key: &'a KC::EItem, @@ -1754,7 +1754,7 @@ impl EncryptedDatabase { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn get_or_put_with_flags<'a, 'txn>( + pub fn get_or_put_with_flags<'a, 'txn, T>( &'txn self, txn: &mut RwTxn, flags: PutFlags, diff --git a/heed/src/envs/encrypted_env.rs b/heed/src/envs/encrypted_env.rs index 4f558acc..d1347e74 100644 --- a/heed/src/envs/encrypted_env.rs +++ b/heed/src/envs/encrypted_env.rs @@ -15,11 +15,11 @@ use crate::{Database, EnvOpenOptions}; /// An environment handle constructed by using [`EnvOpenOptions::open_encrypted`]. #[derive(Clone)] -pub struct EncryptedEnv { - pub(crate) inner: Env, +pub struct EncryptedEnv { + pub(crate) inner: Env, } -impl EncryptedEnv { +impl EncryptedEnv { /// The size of the data file on disk. /// /// # Example @@ -103,7 +103,7 @@ impl EncryptedEnv { } /// Options and flags which can be used to configure how a [`Database`] is opened. - pub fn database_options(&self) -> EncryptedDatabaseOpenOptions { + pub fn database_options(&self) -> EncryptedDatabaseOpenOptions { EncryptedDatabaseOpenOptions::new(self) } @@ -127,7 +127,7 @@ impl EncryptedEnv { /// known as `EINVAL`. pub fn open_database( &self, - rtxn: &RoTxn, + rtxn: &RoTxn, name: Option<&str>, ) -> Result>> where @@ -213,7 +213,7 @@ impl EncryptedEnv { /// map must be resized /// * [`crate::MdbError::ReadersFull`]: a read-only transaction was requested, and the reader lock table is /// full - pub fn read_txn(&self) -> Result { + pub fn read_txn(&self) -> Result> { self.inner.read_txn() } @@ -242,7 +242,7 @@ impl EncryptedEnv { /// map must be resized /// * [`crate::MdbError::ReadersFull`]: a read-only transaction was requested, and the reader lock table is /// full - pub fn static_read_txn(self) -> Result> { + pub fn static_read_txn(self) -> Result> { self.inner.static_read_txn() } @@ -315,11 +315,10 @@ impl EncryptedEnv { } } -unsafe impl Send for EncryptedEnv {} +unsafe impl Send for EncryptedEnv {} +unsafe impl Sync for EncryptedEnv {} -unsafe impl Sync for EncryptedEnv {} - -impl fmt::Debug for EncryptedEnv { +impl fmt::Debug for EncryptedEnv { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("EncryptedEnv") .field("path", &self.inner.path().display()) diff --git a/heed/src/envs/env.rs b/heed/src/envs/env.rs index e1921388..8d2f0793 100644 --- a/heed/src/envs/env.rs +++ b/heed/src/envs/env.rs @@ -43,6 +43,12 @@ impl Env { self.inner.env_ptr } + /// Converts any `Env` into `Env`, useful for wrapping + /// into a `RwTxn` due to the latter always being `WithoutTls`. + /// + /// # Safety + /// + /// Do not use this `Env` to create transactions but only keep it. pub(crate) unsafe fn as_without_tls(&self) -> &Env { unsafe { std::mem::transmute::<&Env, &Env>(self) } } diff --git a/heed/src/envs/env_open_options.rs b/heed/src/envs/env_open_options.rs index 8dbc9471..1ebd2fd7 100644 --- a/heed/src/envs/env_open_options.rs +++ b/heed/src/envs/env_open_options.rs @@ -322,7 +322,7 @@ impl EnvOpenOptions { /// [^7]: /// [^8]: #[cfg(master3)] - pub unsafe fn open_encrypted(&self, key: Key, path: P) -> Result + pub unsafe fn open_encrypted(&self, key: Key, path: P) -> Result> where E: AeadMutInPlace + KeyInit, P: AsRef,