Skip to content

Commit d9503ba

Browse files
committed
Make it work with EncryptedEnv
1 parent 630c94b commit d9503ba

File tree

5 files changed

+67
-62
lines changed

5 files changed

+67
-62
lines changed

heed/src/databases/database.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,13 @@ impl<'e, 'n, T, KC, DC, C> DatabaseOpenOptions<'e, 'n, T, KC, DC, C> {
172172
}
173173
}
174174

175-
impl<KC, DC, C> Clone for DatabaseOpenOptions<'_, '_, KC, DC, C> {
175+
impl<T, KC, DC, C> Clone for DatabaseOpenOptions<'_, '_, T, KC, DC, C> {
176176
fn clone(&self) -> Self {
177177
*self
178178
}
179179
}
180180

181-
impl<KC, DC, C> Copy for DatabaseOpenOptions<'_, '_, KC, DC, C> {}
181+
impl<T, KC, DC, C> Copy for DatabaseOpenOptions<'_, '_, T, KC, DC, C> {}
182182

183183
/// A typed database that accepts only the types it was created with.
184184
///

heed/src/databases/encrypted_database.rs

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -53,29 +53,29 @@ use crate::*;
5353
/// # Ok(()) }
5454
/// ```
5555
#[derive(Debug)]
56-
pub struct EncryptedDatabaseOpenOptions<'e, 'n, KC, DC, C = DefaultComparator> {
57-
inner: DatabaseOpenOptions<'e, 'n, KC, DC, C>,
56+
pub struct EncryptedDatabaseOpenOptions<'e, 'n, T, KC, DC, C = DefaultComparator> {
57+
inner: DatabaseOpenOptions<'e, 'n, T, KC, DC, C>,
5858
}
5959

60-
impl<'e> EncryptedDatabaseOpenOptions<'e, 'static, Unspecified, Unspecified> {
60+
impl<'e, T> EncryptedDatabaseOpenOptions<'e, 'static, T, Unspecified, Unspecified> {
6161
/// Create an options struct to open/create a database with specific flags.
62-
pub fn new(env: &'e EncryptedEnv) -> Self {
62+
pub fn new(env: &'e EncryptedEnv<T>) -> Self {
6363
EncryptedDatabaseOpenOptions { inner: DatabaseOpenOptions::new(&env.inner) }
6464
}
6565
}
6666

67-
impl<'e, 'n, KC, DC, C> EncryptedDatabaseOpenOptions<'e, 'n, KC, DC, C> {
67+
impl<'e, 'n, T, KC, DC, C> EncryptedDatabaseOpenOptions<'e, 'n, T, KC, DC, C> {
6868
/// Change the type of the database.
6969
///
7070
/// The default types are [`Unspecified`] and require a call to [`Database::remap_types`]
7171
/// to use the [`Database`].
72-
pub fn types<NKC, NDC>(self) -> EncryptedDatabaseOpenOptions<'e, 'n, NKC, NDC> {
72+
pub fn types<NKC, NDC>(self) -> EncryptedDatabaseOpenOptions<'e, 'n, T, NKC, NDC> {
7373
EncryptedDatabaseOpenOptions { inner: self.inner.types() }
7474
}
7575
/// Change the customized key compare function of the database.
7676
///
7777
/// By default no customized compare function will be set when opening a database.
78-
pub fn key_comparator<NC>(self) -> EncryptedDatabaseOpenOptions<'e, 'n, KC, DC, NC> {
78+
pub fn key_comparator<NC>(self) -> EncryptedDatabaseOpenOptions<'e, 'n, T, KC, DC, NC> {
7979
EncryptedDatabaseOpenOptions { inner: self.inner.key_comparator() }
8080
}
8181

@@ -111,7 +111,7 @@ impl<'e, 'n, KC, DC, C> EncryptedDatabaseOpenOptions<'e, 'n, KC, DC, C> {
111111
///
112112
/// If not done, you might raise `Io(Os { code: 22, kind: InvalidInput, message: "Invalid argument" })`
113113
/// known as `EINVAL`.
114-
pub fn open(&self, rtxn: &RoTxn) -> Result<Option<EncryptedDatabase<KC, DC, C>>>
114+
pub fn open(&self, rtxn: &RoTxn<T>) -> Result<Option<EncryptedDatabase<KC, DC, C>>>
115115
where
116116
KC: 'static,
117117
DC: 'static,
@@ -139,13 +139,13 @@ impl<'e, 'n, KC, DC, C> EncryptedDatabaseOpenOptions<'e, 'n, KC, DC, C> {
139139
}
140140
}
141141

142-
impl<KC, DC, C> Clone for EncryptedDatabaseOpenOptions<'_, '_, KC, DC, C> {
142+
impl<T, KC, DC, C> Clone for EncryptedDatabaseOpenOptions<'_, '_, T, KC, DC, C> {
143143
fn clone(&self) -> Self {
144144
*self
145145
}
146146
}
147147

148-
impl<KC, DC, C> Copy for EncryptedDatabaseOpenOptions<'_, '_, KC, DC, C> {}
148+
impl<T, KC, DC, C> Copy for EncryptedDatabaseOpenOptions<'_, '_, T, KC, DC, C> {}
149149

150150
/// A typed database that accepts only the types it was created with.
151151
///
@@ -305,9 +305,9 @@ impl<KC, DC, C> EncryptedDatabase<KC, DC, C> {
305305
/// wtxn.commit()?;
306306
/// # Ok(()) }
307307
/// ```
308-
pub fn get<'a, 'txn>(
308+
pub fn get<'a, 'txn, T>(
309309
&self,
310-
txn: &'txn mut RoTxn,
310+
txn: &'txn mut RoTxn<T>,
311311
key: &'a KC::EItem,
312312
) -> Result<Option<DC::DItem>>
313313
where
@@ -369,11 +369,11 @@ impl<KC, DC, C> EncryptedDatabase<KC, DC, C> {
369369
/// wtxn.commit()?;
370370
/// # Ok(()) }
371371
/// ```
372-
pub fn get_duplicates<'a, 'txn>(
372+
pub fn get_duplicates<'a, 'txn, T>(
373373
&self,
374-
txn: &'txn mut RoTxn,
374+
txn: &'txn mut RoTxn<T>,
375375
key: &'a KC::EItem,
376-
) -> Result<Option<RoIter<'txn, KC, DC, MoveOnCurrentKeyDuplicates>>>
376+
) -> Result<Option<RoIter<'txn, T, KC, DC, MoveOnCurrentKeyDuplicates>>>
377377
where
378378
KC: BytesEncode<'a>,
379379
{
@@ -424,9 +424,9 @@ impl<KC, DC, C> EncryptedDatabase<KC, DC, C> {
424424
/// wtxn.commit()?;
425425
/// # Ok(()) }
426426
/// ```
427-
pub fn get_lower_than<'a, 'txn>(
427+
pub fn get_lower_than<'a, 'txn, T>(
428428
&self,
429-
txn: &'txn mut RoTxn,
429+
txn: &'txn mut RoTxn<T>,
430430
key: &'a KC::EItem,
431431
) -> Result<Option<(KC::DItem, DC::DItem)>>
432432
where
@@ -480,9 +480,9 @@ impl<KC, DC, C> EncryptedDatabase<KC, DC, C> {
480480
/// wtxn.commit()?;
481481
/// # Ok(()) }
482482
/// ```
483-
pub fn get_lower_than_or_equal_to<'a, 'txn>(
483+
pub fn get_lower_than_or_equal_to<'a, 'txn, T>(
484484
&self,
485-
txn: &'txn mut RoTxn,
485+
txn: &'txn mut RoTxn<T>,
486486
key: &'a KC::EItem,
487487
) -> Result<Option<(KC::DItem, DC::DItem)>>
488488
where
@@ -536,9 +536,9 @@ impl<KC, DC, C> EncryptedDatabase<KC, DC, C> {
536536
/// wtxn.commit()?;
537537
/// # Ok(()) }
538538
/// ```
539-
pub fn get_greater_than<'a, 'txn>(
539+
pub fn get_greater_than<'a, 'txn, T>(
540540
&self,
541-
txn: &'txn mut RoTxn,
541+
txn: &'txn mut RoTxn<T>,
542542
key: &'a KC::EItem,
543543
) -> Result<Option<(KC::DItem, DC::DItem)>>
544544
where
@@ -592,9 +592,9 @@ impl<KC, DC, C> EncryptedDatabase<KC, DC, C> {
592592
/// wtxn.commit()?;
593593
/// # Ok(()) }
594594
/// ```
595-
pub fn get_greater_than_or_equal_to<'a, 'txn>(
595+
pub fn get_greater_than_or_equal_to<'a, 'txn, T>(
596596
&self,
597-
txn: &'txn mut RoTxn,
597+
txn: &'txn mut RoTxn<T>,
598598
key: &'a KC::EItem,
599599
) -> Result<Option<(KC::DItem, DC::DItem)>>
600600
where
@@ -640,7 +640,7 @@ impl<KC, DC, C> EncryptedDatabase<KC, DC, C> {
640640
/// wtxn.commit()?;
641641
/// # Ok(()) }
642642
/// ```
643-
pub fn first<'txn>(&self, txn: &'txn mut RoTxn) -> Result<Option<(KC::DItem, DC::DItem)>>
643+
pub fn first<'txn, T>(&self, txn: &'txn mut RoTxn<T>) -> Result<Option<(KC::DItem, DC::DItem)>>
644644
where
645645
KC: BytesDecode<'txn>,
646646
DC: BytesDecode<'txn>,
@@ -684,7 +684,7 @@ impl<KC, DC, C> EncryptedDatabase<KC, DC, C> {
684684
/// wtxn.commit()?;
685685
/// # Ok(()) }
686686
/// ```
687-
pub fn last<'txn>(&self, txn: &'txn mut RoTxn) -> Result<Option<(KC::DItem, DC::DItem)>>
687+
pub fn last<'txn, T>(&self, txn: &'txn mut RoTxn<T>) -> Result<Option<(KC::DItem, DC::DItem)>>
688688
where
689689
KC: BytesDecode<'txn>,
690690
DC: BytesDecode<'txn>,
@@ -731,7 +731,7 @@ impl<KC, DC, C> EncryptedDatabase<KC, DC, C> {
731731
/// wtxn.commit()?;
732732
/// # Ok(()) }
733733
/// ```
734-
pub fn len(&self, txn: &RoTxn) -> Result<u64> {
734+
pub fn len<T>(&self, txn: &RoTxn<T>) -> Result<u64> {
735735
self.inner.len(txn)
736736
}
737737

@@ -774,7 +774,7 @@ impl<KC, DC, C> EncryptedDatabase<KC, DC, C> {
774774
/// wtxn.commit()?;
775775
/// # Ok(()) }
776776
/// ```
777-
pub fn is_empty(&self, txn: &RoTxn) -> Result<bool> {
777+
pub fn is_empty<T>(&self, txn: &RoTxn<T>) -> Result<bool> {
778778
self.inner.is_empty(txn)
779779
}
780780

@@ -816,7 +816,7 @@ impl<KC, DC, C> EncryptedDatabase<KC, DC, C> {
816816
/// wtxn.commit()?;
817817
/// # Ok(()) }
818818
/// ```
819-
pub fn stat(&self, txn: &RoTxn) -> Result<DatabaseStat> {
819+
pub fn stat<T>(&self, txn: &RoTxn<T>) -> Result<DatabaseStat> {
820820
self.inner.stat(txn)
821821
}
822822

@@ -860,7 +860,7 @@ impl<KC, DC, C> EncryptedDatabase<KC, DC, C> {
860860
/// wtxn.commit()?;
861861
/// # Ok(()) }
862862
/// ```
863-
pub fn iter<'txn>(&self, txn: &'txn mut RoTxn) -> Result<RoIter<'txn, KC, DC>> {
863+
pub fn iter<'txn, T>(&self, txn: &'txn mut RoTxn<T>) -> Result<RoIter<'txn, T, KC, DC>> {
864864
self.inner.iter(txn)
865865
}
866866

@@ -914,7 +914,7 @@ impl<KC, DC, C> EncryptedDatabase<KC, DC, C> {
914914
/// wtxn.commit()?;
915915
/// # Ok(()) }
916916
/// ```
917-
pub fn iter_mut<'txn>(&self, txn: &'txn mut RwTxn) -> Result<RwIter<'txn, KC, DC>> {
917+
pub fn iter_mut<'txn, T>(&self, txn: &'txn mut RwTxn) -> Result<RwIter<'txn, KC, DC>> {
918918
self.inner.iter_mut(txn)
919919
}
920920

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

@@ -1013,7 +1013,7 @@ impl<KC, DC, C> EncryptedDatabase<KC, DC, C> {
10131013
/// wtxn.commit()?;
10141014
/// # Ok(()) }
10151015
/// ```
1016-
pub fn rev_iter_mut<'txn>(&self, txn: &'txn mut RwTxn) -> Result<RwRevIter<'txn, KC, DC>> {
1016+
pub fn rev_iter_mut<'txn, T>(&self, txn: &'txn mut RwTxn) -> Result<RwRevIter<'txn, KC, DC>> {
10171017
self.inner.rev_iter_mut(txn)
10181018
}
10191019

@@ -1060,11 +1060,11 @@ impl<KC, DC, C> EncryptedDatabase<KC, DC, C> {
10601060
/// wtxn.commit()?;
10611061
/// # Ok(()) }
10621062
/// ```
1063-
pub fn range<'a, 'txn, R>(
1063+
pub fn range<'a, 'txn, R, T>(
10641064
&self,
1065-
txn: &'txn mut RoTxn,
1065+
txn: &'txn mut RoTxn<T>,
10661066
range: &'a R,
1067-
) -> Result<RoRange<'txn, KC, DC, C>>
1067+
) -> Result<RoRange<'txn, T, KC, DC, C>>
10681068
where
10691069
KC: BytesEncode<'a>,
10701070
R: RangeBounds<KC::EItem>,
@@ -1182,11 +1182,11 @@ impl<KC, DC, C> EncryptedDatabase<KC, DC, C> {
11821182
/// wtxn.commit()?;
11831183
/// # Ok(()) }
11841184
/// ```
1185-
pub fn rev_range<'a, 'txn, R>(
1185+
pub fn rev_range<'a, 'txn, R, T>(
11861186
&self,
1187-
txn: &'txn mut RoTxn,
1187+
txn: &'txn mut RoTxn<T>,
11881188
range: &'a R,
1189-
) -> Result<RoRevRange<'txn, KC, DC, C>>
1189+
) -> Result<RoRevRange<'txn, T, KC, DC, C>>
11901190
where
11911191
KC: BytesEncode<'a>,
11921192
R: RangeBounds<KC::EItem>,
@@ -1305,11 +1305,11 @@ impl<KC, DC, C> EncryptedDatabase<KC, DC, C> {
13051305
/// wtxn.commit()?;
13061306
/// # Ok(()) }
13071307
/// ```
1308-
pub fn prefix_iter<'a, 'txn>(
1308+
pub fn prefix_iter<'a, 'txn, T>(
13091309
&self,
1310-
txn: &'txn mut RoTxn,
1310+
txn: &'txn mut RoTxn<T>,
13111311
prefix: &'a KC::EItem,
1312-
) -> Result<RoPrefix<'txn, KC, DC, C>>
1312+
) -> Result<RoPrefix<'txn, T, KC, DC, C>>
13131313
where
13141314
KC: BytesEncode<'a>,
13151315
C: LexicographicComparator,
@@ -1372,7 +1372,7 @@ impl<KC, DC, C> EncryptedDatabase<KC, DC, C> {
13721372
/// wtxn.commit()?;
13731373
/// # Ok(()) }
13741374
/// ```
1375-
pub fn prefix_iter_mut<'a, 'txn>(
1375+
pub fn prefix_iter_mut<'a, 'txn, T>(
13761376
&self,
13771377
txn: &'txn mut RwTxn,
13781378
prefix: &'a KC::EItem,
@@ -1429,11 +1429,11 @@ impl<KC, DC, C> EncryptedDatabase<KC, DC, C> {
14291429
/// wtxn.commit()?;
14301430
/// # Ok(()) }
14311431
/// ```
1432-
pub fn rev_prefix_iter<'a, 'txn>(
1432+
pub fn rev_prefix_iter<'a, 'txn, T>(
14331433
&self,
1434-
txn: &'txn mut RoTxn,
1434+
txn: &'txn mut RoTxn<T>,
14351435
prefix: &'a KC::EItem,
1436-
) -> Result<RoRevPrefix<'txn, KC, DC, C>>
1436+
) -> Result<RoRevPrefix<'txn, T, KC, DC, C>>
14371437
where
14381438
KC: BytesEncode<'a>,
14391439
C: LexicographicComparator,
@@ -1496,7 +1496,7 @@ impl<KC, DC, C> EncryptedDatabase<KC, DC, C> {
14961496
/// wtxn.commit()?;
14971497
/// # Ok(()) }
14981498
/// ```
1499-
pub fn rev_prefix_iter_mut<'a, 'txn>(
1499+
pub fn rev_prefix_iter_mut<'a, 'txn, T>(
15001500
&self,
15011501
txn: &'txn mut RwTxn,
15021502
prefix: &'a KC::EItem,
@@ -1707,7 +1707,7 @@ impl<KC, DC, C> EncryptedDatabase<KC, DC, C> {
17071707
/// wtxn.commit()?;
17081708
/// # Ok(()) }
17091709
/// ```
1710-
pub fn get_or_put<'a, 'txn>(
1710+
pub fn get_or_put<'a, 'txn, T>(
17111711
&'txn self,
17121712
txn: &mut RwTxn,
17131713
key: &'a KC::EItem,
@@ -1754,7 +1754,7 @@ impl<KC, DC, C> EncryptedDatabase<KC, DC, C> {
17541754
/// wtxn.commit()?;
17551755
/// # Ok(()) }
17561756
/// ```
1757-
pub fn get_or_put_with_flags<'a, 'txn>(
1757+
pub fn get_or_put_with_flags<'a, 'txn, T>(
17581758
&'txn self,
17591759
txn: &mut RwTxn,
17601760
flags: PutFlags,

heed/src/envs/encrypted_env.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ use crate::{Database, EnvOpenOptions};
1515

1616
/// An environment handle constructed by using [`EnvOpenOptions::open_encrypted`].
1717
#[derive(Clone)]
18-
pub struct EncryptedEnv {
19-
pub(crate) inner: Env,
18+
pub struct EncryptedEnv<T> {
19+
pub(crate) inner: Env<T>,
2020
}
2121

22-
impl EncryptedEnv {
22+
impl<T> EncryptedEnv<T> {
2323
/// The size of the data file on disk.
2424
///
2525
/// # Example
@@ -103,7 +103,7 @@ impl EncryptedEnv {
103103
}
104104

105105
/// Options and flags which can be used to configure how a [`Database`] is opened.
106-
pub fn database_options(&self) -> EncryptedDatabaseOpenOptions<Unspecified, Unspecified> {
106+
pub fn database_options(&self) -> EncryptedDatabaseOpenOptions<T, Unspecified, Unspecified> {
107107
EncryptedDatabaseOpenOptions::new(self)
108108
}
109109

@@ -127,7 +127,7 @@ impl EncryptedEnv {
127127
/// known as `EINVAL`.
128128
pub fn open_database<KC, DC>(
129129
&self,
130-
rtxn: &RoTxn,
130+
rtxn: &RoTxn<T>,
131131
name: Option<&str>,
132132
) -> Result<Option<EncryptedDatabase<KC, DC>>>
133133
where
@@ -213,7 +213,7 @@ impl EncryptedEnv {
213213
/// map must be resized
214214
/// * [`crate::MdbError::ReadersFull`]: a read-only transaction was requested, and the reader lock table is
215215
/// full
216-
pub fn read_txn(&self) -> Result<RoTxn> {
216+
pub fn read_txn(&self) -> Result<RoTxn<T>> {
217217
self.inner.read_txn()
218218
}
219219

@@ -242,7 +242,7 @@ impl EncryptedEnv {
242242
/// map must be resized
243243
/// * [`crate::MdbError::ReadersFull`]: a read-only transaction was requested, and the reader lock table is
244244
/// full
245-
pub fn static_read_txn(self) -> Result<RoTxn<'static>> {
245+
pub fn static_read_txn(self) -> Result<RoTxn<'static, T>> {
246246
self.inner.static_read_txn()
247247
}
248248

@@ -315,11 +315,10 @@ impl EncryptedEnv {
315315
}
316316
}
317317

318-
unsafe impl Send for EncryptedEnv {}
318+
unsafe impl<T> Send for EncryptedEnv<T> {}
319+
unsafe impl<T> Sync for EncryptedEnv<T> {}
319320

320-
unsafe impl Sync for EncryptedEnv {}
321-
322-
impl fmt::Debug for EncryptedEnv {
321+
impl<T> fmt::Debug for EncryptedEnv<T> {
323322
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
324323
f.debug_struct("EncryptedEnv")
325324
.field("path", &self.inner.path().display())

0 commit comments

Comments
 (0)