diff --git a/heed/src/cursor.rs b/heed/src/cursor.rs index 8c859316..9f4fd0a1 100644 --- a/heed/src/cursor.rs +++ b/heed/src/cursor.rs @@ -5,14 +5,14 @@ use crate::mdb::error::mdb_result; use crate::mdb::ffi; use crate::*; -pub struct RoCursor<'txn> { +pub struct RoCursor<'txn, T> { cursor: *mut ffi::MDB_cursor, - _marker: marker::PhantomData<&'txn ()>, + _marker: marker::PhantomData<&'txn T>, } -impl<'txn> RoCursor<'txn> { +impl<'txn, T> RoCursor<'txn, T> { // TODO should I ask for a &mut RoTxn<'_, T>, here? - pub(crate) fn new(txn: &'txn RoTxn<'_, T>, dbi: ffi::MDB_dbi) -> Result> { + pub(crate) fn new(txn: &'txn RoTxn<'_, T>, dbi: ffi::MDB_dbi) -> Result> { 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))? } @@ -237,14 +237,14 @@ impl<'txn> RoCursor<'txn> { } } -impl Drop for RoCursor<'_> { +impl Drop for RoCursor<'_, T> { fn drop(&mut self) { unsafe { ffi::mdb_cursor_close(self.cursor) } } } pub struct RwCursor<'txn> { - cursor: RoCursor<'txn>, + cursor: RoCursor<'txn, WithoutTls>, } impl<'txn> RwCursor<'txn> { @@ -404,7 +404,7 @@ impl<'txn> RwCursor<'txn> { } impl<'txn> Deref for RwCursor<'txn> { - type Target = RoCursor<'txn>; + type Target = RoCursor<'txn, WithoutTls>; fn deref(&self) -> &Self::Target { &self.cursor diff --git a/heed/src/databases/database.rs b/heed/src/databases/database.rs index 011de40f..aa39e283 100644 --- a/heed/src/databases/database.rs +++ b/heed/src/databases/database.rs @@ -433,7 +433,7 @@ impl Database { &self, txn: &'txn RoTxn, key: &'a KC::EItem, - ) -> Result>> + ) -> Result>> where KC: BytesEncode<'a>, { @@ -1026,7 +1026,7 @@ impl Database { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn iter<'txn, T>(&self, txn: &'txn RoTxn) -> Result> { + pub fn iter<'txn, T>(&self, txn: &'txn RoTxn) -> Result> { assert_eq_env_db_txn!(self, txn); RoCursor::new(txn, self.dbi).map(|cursor| RoIter::new(cursor)) } @@ -1128,7 +1128,7 @@ impl Database { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn rev_iter<'txn, T>(&self, txn: &'txn RoTxn) -> Result> { + pub fn rev_iter<'txn, T>(&self, txn: &'txn RoTxn) -> Result> { assert_eq_env_db_txn!(self, txn); RoCursor::new(txn, self.dbi).map(|cursor| RoRevIter::new(cursor)) @@ -1239,7 +1239,7 @@ impl Database { &self, txn: &'txn RoTxn, range: &'a R, - ) -> Result> + ) -> Result> where KC: BytesEncode<'a>, R: RangeBounds, @@ -1412,7 +1412,7 @@ impl Database { &self, txn: &'txn RoTxn, range: &'a R, - ) -> Result> + ) -> Result> where KC: BytesEncode<'a>, R: RangeBounds, @@ -1587,7 +1587,7 @@ impl Database { &self, txn: &'txn RoTxn, prefix: &'a KC::EItem, - ) -> Result> + ) -> Result> where KC: BytesEncode<'a>, C: LexicographicComparator, @@ -1720,7 +1720,7 @@ impl Database { &self, txn: &'txn RoTxn<'_, T>, prefix: &'a KC::EItem, - ) -> Result> + ) -> Result> where KC: BytesEncode<'a>, C: LexicographicComparator, diff --git a/heed/src/databases/encrypted_database.rs b/heed/src/databases/encrypted_database.rs index e2ba65d6..8388f428 100644 --- a/heed/src/databases/encrypted_database.rs +++ b/heed/src/databases/encrypted_database.rs @@ -374,7 +374,7 @@ impl EncryptedDatabase { &self, txn: &'txn mut RoTxn, key: &'a KC::EItem, - ) -> Result>> + ) -> Result>> where KC: BytesEncode<'a>, { @@ -862,7 +862,7 @@ impl EncryptedDatabase { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn iter<'txn, T>(&self, txn: &'txn mut RoTxn) -> Result> { + pub fn iter<'txn, T>(&self, txn: &'txn mut RoTxn) -> Result> { self.inner.iter(txn) } @@ -961,7 +961,7 @@ impl EncryptedDatabase { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn rev_iter<'txn, T>(&self, txn: &'txn mut RoTxn) -> Result> { + pub fn rev_iter<'txn, T>(&self, txn: &'txn mut RoTxn) -> Result> { self.inner.rev_iter(txn) } @@ -1068,7 +1068,7 @@ impl EncryptedDatabase { &self, txn: &'txn mut RoTxn, range: &'a R, - ) -> Result> + ) -> Result> where KC: BytesEncode<'a>, R: RangeBounds, @@ -1191,7 +1191,7 @@ impl EncryptedDatabase { &self, txn: &'txn mut RoTxn, range: &'a R, - ) -> Result> + ) -> Result> where KC: BytesEncode<'a>, R: RangeBounds, @@ -1315,7 +1315,7 @@ impl EncryptedDatabase { &self, txn: &'txn mut RoTxn, prefix: &'a KC::EItem, - ) -> Result> + ) -> Result> where KC: BytesEncode<'a>, C: LexicographicComparator, @@ -1440,7 +1440,7 @@ impl EncryptedDatabase { &self, txn: &'txn mut RoTxn, prefix: &'a KC::EItem, - ) -> Result> + ) -> Result> where KC: BytesEncode<'a>, C: LexicographicComparator, diff --git a/heed/src/iterator/iter.rs b/heed/src/iterator/iter.rs index 503c86d8..4f7d5c07 100644 --- a/heed/src/iterator/iter.rs +++ b/heed/src/iterator/iter.rs @@ -7,14 +7,14 @@ use crate::iteration_method::{IterationMethod, MoveBetweenKeys, MoveThroughDupli use crate::*; /// A read-only iterator structure. -pub struct RoIter<'txn, KC, DC, IM = MoveThroughDuplicateValues> { - cursor: RoCursor<'txn>, +pub struct RoIter<'txn, T, KC, DC, IM = MoveThroughDuplicateValues> { + cursor: RoCursor<'txn, T>, move_on_first: bool, _phantom: marker::PhantomData<(KC, DC, IM)>, } -impl<'txn, KC, DC, IM> RoIter<'txn, KC, DC, IM> { - pub(crate) fn new(cursor: RoCursor<'txn>) -> RoIter<'txn, KC, DC, IM> { +impl<'txn, T, KC, DC, IM> RoIter<'txn, T, KC, DC, IM> { + pub(crate) fn new(cursor: RoCursor<'txn, T>) -> RoIter<'txn, T, KC, DC, IM> { RoIter { cursor, move_on_first: true, _phantom: marker::PhantomData } } @@ -63,7 +63,7 @@ impl<'txn, KC, DC, IM> RoIter<'txn, KC, DC, IM> { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn move_between_keys(self) -> RoIter<'txn, KC, DC, MoveBetweenKeys> { + pub fn move_between_keys(self) -> RoIter<'txn, T, KC, DC, MoveBetweenKeys> { RoIter { cursor: self.cursor, move_on_first: self.move_on_first, @@ -119,7 +119,9 @@ impl<'txn, KC, DC, IM> RoIter<'txn, KC, DC, IM> { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn move_through_duplicate_values(self) -> RoIter<'txn, KC, DC, MoveThroughDuplicateValues> { + pub fn move_through_duplicate_values( + self, + ) -> RoIter<'txn, T, KC, DC, MoveThroughDuplicateValues> { RoIter { cursor: self.cursor, move_on_first: self.move_on_first, @@ -128,7 +130,7 @@ impl<'txn, KC, DC, IM> RoIter<'txn, KC, DC, IM> { } /// Change the codec types of this iterator, specifying the codecs. - pub fn remap_types(self) -> RoIter<'txn, KC2, DC2, IM> { + pub fn remap_types(self) -> RoIter<'txn, T, KC2, DC2, IM> { RoIter { cursor: self.cursor, move_on_first: self.move_on_first, @@ -137,22 +139,22 @@ impl<'txn, KC, DC, IM> RoIter<'txn, KC, DC, IM> { } /// Change the key codec type of this iterator, specifying the new codec. - pub fn remap_key_type(self) -> RoIter<'txn, KC2, DC, IM> { + pub fn remap_key_type(self) -> RoIter<'txn, T, KC2, DC, IM> { self.remap_types::() } /// Change the data codec type of this iterator, specifying the new codec. - pub fn remap_data_type(self) -> RoIter<'txn, KC, DC2, IM> { + pub fn remap_data_type(self) -> RoIter<'txn, T, KC, DC2, IM> { self.remap_types::() } /// Wrap the data bytes into a lazy decoder. - pub fn lazily_decode_data(self) -> RoIter<'txn, KC, LazyDecode, IM> { + pub fn lazily_decode_data(self) -> RoIter<'txn, T, KC, LazyDecode, IM> { self.remap_types::>() } } -impl<'txn, KC, DC, IM> Iterator for RoIter<'txn, KC, DC, IM> +impl<'txn, T, KC, DC, IM> Iterator for RoIter<'txn, T, KC, DC, IM> where KC: BytesDecode<'txn>, DC: BytesDecode<'txn>, @@ -208,8 +210,8 @@ impl fmt::Debug for RoIter<'_, KC, DC, IM> { } } -/// A `RoIter` is `Send` only if the `RoTxn` is. -unsafe impl Send for RoIter<'_, KC, DC, IM> {} +// Only implement Send if the transaction is Send (WithoutTls) +unsafe impl Send for RoIter<'_, WithoutTls, KC, DC, IM> {} /// A read-write iterator structure. pub struct RwIter<'txn, KC, DC, IM = MoveThroughDuplicateValues> { @@ -441,21 +443,21 @@ impl fmt::Debug for RwIter<'_, KC, DC, IM> { } /// A reverse read-only iterator structure. -pub struct RoRevIter<'txn, KC, DC, IM = MoveThroughDuplicateValues> { - cursor: RoCursor<'txn>, +pub struct RoRevIter<'txn, T, KC, DC, IM = MoveThroughDuplicateValues> { + cursor: RoCursor<'txn, T>, move_on_last: bool, _phantom: marker::PhantomData<(KC, DC, IM)>, } -impl<'txn, KC, DC, IM> RoRevIter<'txn, KC, DC, IM> { - pub(crate) fn new(cursor: RoCursor<'txn>) -> RoRevIter<'txn, KC, DC, IM> { +impl<'txn, T, KC, DC, IM> RoRevIter<'txn, T, KC, DC, IM> { + pub(crate) fn new(cursor: RoCursor<'txn, T>) -> RoRevIter<'txn, T, KC, DC, IM> { RoRevIter { cursor, move_on_last: true, _phantom: marker::PhantomData } } /// Move on the first value of keys, ignoring duplicate values. /// /// For more info, see [`RoIter::move_between_keys`]. - pub fn move_between_keys(self) -> RoRevIter<'txn, KC, DC, MoveBetweenKeys> { + pub fn move_between_keys(self) -> RoRevIter<'txn, T, KC, DC, MoveBetweenKeys> { RoRevIter { cursor: self.cursor, move_on_last: self.move_on_last, @@ -468,7 +470,7 @@ impl<'txn, KC, DC, IM> RoRevIter<'txn, KC, DC, IM> { /// For more info, see [`RoIter::move_through_duplicate_values`]. pub fn move_through_duplicate_values( self, - ) -> RoRevIter<'txn, KC, DC, MoveThroughDuplicateValues> { + ) -> RoRevIter<'txn, T, KC, DC, MoveThroughDuplicateValues> { RoRevIter { cursor: self.cursor, move_on_last: self.move_on_last, @@ -477,7 +479,7 @@ impl<'txn, KC, DC, IM> RoRevIter<'txn, KC, DC, IM> { } /// Change the codec types of this iterator, specifying the codecs. - pub fn remap_types(self) -> RoRevIter<'txn, KC2, DC2, IM> { + pub fn remap_types(self) -> RoRevIter<'txn, T, KC2, DC2, IM> { RoRevIter { cursor: self.cursor, move_on_last: self.move_on_last, @@ -486,22 +488,22 @@ impl<'txn, KC, DC, IM> RoRevIter<'txn, KC, DC, IM> { } /// Change the key codec type of this iterator, specifying the new codec. - pub fn remap_key_type(self) -> RoRevIter<'txn, KC2, DC, IM> { + pub fn remap_key_type(self) -> RoRevIter<'txn, T, KC2, DC, IM> { self.remap_types::() } /// Change the data codec type of this iterator, specifying the new codec. - pub fn remap_data_type(self) -> RoRevIter<'txn, KC, DC2, IM> { + pub fn remap_data_type(self) -> RoRevIter<'txn, T, KC, DC2, IM> { self.remap_types::() } /// Wrap the data bytes into a lazy decoder. - pub fn lazily_decode_data(self) -> RoRevIter<'txn, KC, LazyDecode, IM> { + pub fn lazily_decode_data(self) -> RoRevIter<'txn, T, KC, LazyDecode, IM> { self.remap_types::>() } } -impl<'txn, KC, DC, IM> Iterator for RoRevIter<'txn, KC, DC, IM> +impl<'txn, T, KC, DC, IM> Iterator for RoRevIter<'txn, T, KC, DC, IM> where KC: BytesDecode<'txn>, DC: BytesDecode<'txn>, @@ -557,7 +559,8 @@ impl fmt::Debug for RoRevIter<'_, KC, DC, IM> { } } -unsafe impl Send for RoRevIter<'_, KC, DC, IM> {} +// Only implement Send if the transaction is Send (WithoutTls) +unsafe impl Send for RoRevIter<'_, WithoutTls, KC, DC, IM> {} /// A reverse read-write iterator structure. pub struct RwRevIter<'txn, KC, DC, IM = MoveThroughDuplicateValues> { diff --git a/heed/src/iterator/prefix.rs b/heed/src/iterator/prefix.rs index 61239a26..61b69af0 100644 --- a/heed/src/iterator/prefix.rs +++ b/heed/src/iterator/prefix.rs @@ -47,8 +47,8 @@ fn retreat_prefix(bytes: &mut [u8]) -> bool { true } -fn move_on_prefix_end<'txn, C: LexicographicComparator>( - cursor: &mut RoCursor<'txn>, +fn move_on_prefix_end<'txn, T, C: LexicographicComparator>( + cursor: &mut RoCursor<'txn, T>, prefix: &mut [u8], ) -> Result> { if advance_prefix::(prefix) { @@ -64,22 +64,25 @@ fn move_on_prefix_end<'txn, C: LexicographicComparator>( } /// A read-only prefix iterator structure. -pub struct RoPrefix<'txn, KC, DC, C = DefaultComparator, IM = MoveThroughDuplicateValues> { - cursor: RoCursor<'txn>, +pub struct RoPrefix<'txn, T, KC, DC, C = DefaultComparator, IM = MoveThroughDuplicateValues> { + cursor: RoCursor<'txn, T>, prefix: Vec, move_on_first: bool, _phantom: marker::PhantomData<(KC, DC, C, IM)>, } -impl<'txn, KC, DC, C, IM> RoPrefix<'txn, KC, DC, C, IM> { - pub(crate) fn new(cursor: RoCursor<'txn>, prefix: Vec) -> RoPrefix<'txn, KC, DC, C, IM> { +impl<'txn, T, KC, DC, C, IM> RoPrefix<'txn, T, KC, DC, C, IM> { + pub(crate) fn new( + cursor: RoCursor<'txn, T>, + prefix: Vec, + ) -> RoPrefix<'txn, T, KC, DC, C, IM> { RoPrefix { cursor, prefix, move_on_first: true, _phantom: marker::PhantomData } } /// Move on the first value of keys, ignoring duplicate values. /// /// For more info, see [`RoIter::move_between_keys`]. - pub fn move_between_keys(self) -> RoPrefix<'txn, KC, DC, C, MoveBetweenKeys> { + pub fn move_between_keys(self) -> RoPrefix<'txn, T, KC, DC, C, MoveBetweenKeys> { RoPrefix { cursor: self.cursor, prefix: self.prefix, @@ -93,7 +96,7 @@ impl<'txn, KC, DC, C, IM> RoPrefix<'txn, KC, DC, C, IM> { /// For more info, see [`RoIter::move_through_duplicate_values`]. pub fn move_through_duplicate_values( self, - ) -> RoPrefix<'txn, KC, DC, C, MoveThroughDuplicateValues> { + ) -> RoPrefix<'txn, T, KC, DC, C, MoveThroughDuplicateValues> { RoPrefix { cursor: self.cursor, prefix: self.prefix, @@ -103,7 +106,7 @@ impl<'txn, KC, DC, C, IM> RoPrefix<'txn, KC, DC, C, IM> { } /// Change the codec types of this iterator, specifying the codecs. - pub fn remap_types(self) -> RoPrefix<'txn, KC2, DC2, C, IM> { + pub fn remap_types(self) -> RoPrefix<'txn, T, KC2, DC2, C, IM> { RoPrefix { cursor: self.cursor, prefix: self.prefix, @@ -113,22 +116,22 @@ impl<'txn, KC, DC, C, IM> RoPrefix<'txn, KC, DC, C, IM> { } /// Change the key codec type of this iterator, specifying the new codec. - pub fn remap_key_type(self) -> RoPrefix<'txn, KC2, DC, C, IM> { + pub fn remap_key_type(self) -> RoPrefix<'txn, T, KC2, DC, C, IM> { self.remap_types::() } /// Change the data codec type of this iterator, specifying the new codec. - pub fn remap_data_type(self) -> RoPrefix<'txn, KC, DC2, C, IM> { + pub fn remap_data_type(self) -> RoPrefix<'txn, T, KC, DC2, C, IM> { self.remap_types::() } /// Wrap the data bytes into a lazy decoder. - pub fn lazily_decode_data(self) -> RoPrefix<'txn, KC, LazyDecode, C, IM> { + pub fn lazily_decode_data(self) -> RoPrefix<'txn, T, KC, LazyDecode, C, IM> { self.remap_types::>() } } -impl<'txn, KC, DC, C, IM> Iterator for RoPrefix<'txn, KC, DC, C, IM> +impl<'txn, T, KC, DC, C, IM> Iterator for RoPrefix<'txn, T, KC, DC, C, IM> where KC: BytesDecode<'txn>, DC: BytesDecode<'txn>, @@ -163,11 +166,11 @@ where fn last(mut self) -> Option { let result = if self.move_on_first { - move_on_prefix_end::(&mut self.cursor, &mut self.prefix) + move_on_prefix_end::<_, C>(&mut self.cursor, &mut self.prefix) } else { match ( self.cursor.current(), - move_on_prefix_end::(&mut self.cursor, &mut self.prefix), + move_on_prefix_end::<_, C>(&mut self.cursor, &mut self.prefix), ) { (Ok(Some((ckey, _))), Ok(Some((key, data)))) if ckey != key => { Ok(Some((key, data))) @@ -200,6 +203,7 @@ impl fmt::Debug for RoPrefix<'_, KC, DC, C, IM> { } } +// Only implement Send if the transaction is Send (WithoutTls) unsafe impl Send for RoPrefix<'_, WithoutTls, KC, DC, IM> {} /// A read-write prefix iterator structure. @@ -416,11 +420,11 @@ where fn last(mut self) -> Option { let result = if self.move_on_first { - move_on_prefix_end::(&mut self.cursor, &mut self.prefix) + move_on_prefix_end::<_, C>(&mut self.cursor, &mut self.prefix) } else { match ( self.cursor.current(), - move_on_prefix_end::(&mut self.cursor, &mut self.prefix), + move_on_prefix_end::<_, C>(&mut self.cursor, &mut self.prefix), ) { (Ok(Some((ckey, _))), Ok(Some((key, data)))) if ckey != key => { Ok(Some((key, data))) @@ -454,22 +458,25 @@ impl fmt::Debug for RwPrefix<'_, KC, DC, C, IM> { } /// A reverse read-only prefix iterator structure. -pub struct RoRevPrefix<'txn, KC, DC, C = DefaultComparator, IM = MoveThroughDuplicateValues> { - cursor: RoCursor<'txn>, +pub struct RoRevPrefix<'txn, T, KC, DC, C = DefaultComparator, IM = MoveThroughDuplicateValues> { + cursor: RoCursor<'txn, T>, prefix: Vec, move_on_last: bool, _phantom: marker::PhantomData<(KC, DC, C, IM)>, } -impl<'txn, KC, DC, C, IM> RoRevPrefix<'txn, KC, DC, C, IM> { - pub(crate) fn new(cursor: RoCursor<'txn>, prefix: Vec) -> RoRevPrefix<'txn, KC, DC, C, IM> { +impl<'txn, T, KC, DC, C, IM> RoRevPrefix<'txn, T, KC, DC, C, IM> { + pub(crate) fn new( + cursor: RoCursor<'txn, T>, + prefix: Vec, + ) -> RoRevPrefix<'txn, T, KC, DC, C, IM> { RoRevPrefix { cursor, prefix, move_on_last: true, _phantom: marker::PhantomData } } /// Move on the first value of keys, ignoring duplicate values. /// /// For more info, see [`RoIter::move_between_keys`]. - pub fn move_between_keys(self) -> RoRevPrefix<'txn, KC, DC, C, MoveBetweenKeys> { + pub fn move_between_keys(self) -> RoRevPrefix<'txn, T, KC, DC, C, MoveBetweenKeys> { RoRevPrefix { cursor: self.cursor, prefix: self.prefix, @@ -483,7 +490,7 @@ impl<'txn, KC, DC, C, IM> RoRevPrefix<'txn, KC, DC, C, IM> { /// For more info, see [`RoIter::move_through_duplicate_values`]. pub fn move_through_duplicate_values( self, - ) -> RoRevPrefix<'txn, KC, DC, C, MoveThroughDuplicateValues> { + ) -> RoRevPrefix<'txn, T, KC, DC, C, MoveThroughDuplicateValues> { RoRevPrefix { cursor: self.cursor, prefix: self.prefix, @@ -493,7 +500,7 @@ impl<'txn, KC, DC, C, IM> RoRevPrefix<'txn, KC, DC, C, IM> { } /// Change the codec types of this iterator, specifying the codecs. - pub fn remap_types(self) -> RoRevPrefix<'txn, KC2, DC2, C, IM> { + pub fn remap_types(self) -> RoRevPrefix<'txn, T, KC2, DC2, C, IM> { RoRevPrefix { cursor: self.cursor, prefix: self.prefix, @@ -503,22 +510,22 @@ impl<'txn, KC, DC, C, IM> RoRevPrefix<'txn, KC, DC, C, IM> { } /// Change the key codec type of this iterator, specifying the new codec. - pub fn remap_key_type(self) -> RoRevPrefix<'txn, KC2, DC, C, IM> { + pub fn remap_key_type(self) -> RoRevPrefix<'txn, T, KC2, DC, C, IM> { self.remap_types::() } /// Change the data codec type of this iterator, specifying the new codec. - pub fn remap_data_type(self) -> RoRevPrefix<'txn, KC, DC2, C, IM> { + pub fn remap_data_type(self) -> RoRevPrefix<'txn, T, KC, DC2, C, IM> { self.remap_types::() } /// Wrap the data bytes into a lazy decoder. - pub fn lazily_decode_data(self) -> RoRevPrefix<'txn, KC, LazyDecode, C, IM> { + pub fn lazily_decode_data(self) -> RoRevPrefix<'txn, T, KC, LazyDecode, C, IM> { self.remap_types::>() } } -impl<'txn, KC, DC, C, IM> Iterator for RoRevPrefix<'txn, KC, DC, C, IM> +impl<'txn, T, KC, DC, C, IM> Iterator for RoRevPrefix<'txn, T, KC, DC, C, IM> where KC: BytesDecode<'txn>, DC: BytesDecode<'txn>, @@ -530,7 +537,7 @@ where fn next(&mut self) -> Option { let result = if self.move_on_last { self.move_on_last = false; - move_on_prefix_end::(&mut self.cursor, &mut self.prefix) + move_on_prefix_end::<_, C>(&mut self.cursor, &mut self.prefix) } else { self.cursor.move_on_prev(IM::MOVE_OPERATION) }; @@ -583,12 +590,13 @@ where } } -impl fmt::Debug for RoRevPrefix<'_, KC, DC, C, IM> { +impl fmt::Debug for RoRevPrefix<'_, T, KC, DC, C, IM> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("RoRevPrefix").finish() } } +// Only implement Send if the transaction is Send (WithoutTls) unsafe impl Send for RoRevPrefix<'_, WithoutTls, KC, DC, IM> {} /// A reverse read-write prefix iterator structure. @@ -782,7 +790,7 @@ where fn next(&mut self) -> Option { let result = if self.move_on_last { self.move_on_last = false; - move_on_prefix_end::(&mut self.cursor, &mut self.prefix) + move_on_prefix_end::<_, C>(&mut self.cursor, &mut self.prefix) } else { self.cursor.move_on_prev(IM::MOVE_OPERATION) }; diff --git a/heed/src/iterator/range.rs b/heed/src/iterator/range.rs index d0524a9d..dcc5bee5 100644 --- a/heed/src/iterator/range.rs +++ b/heed/src/iterator/range.rs @@ -8,8 +8,8 @@ use crate::cursor::MoveOperation; use crate::iteration_method::{IterationMethod, MoveBetweenKeys, MoveThroughDuplicateValues}; use crate::*; -fn move_on_range_end<'txn>( - cursor: &mut RoCursor<'txn>, +fn move_on_range_end<'txn, T>( + cursor: &mut RoCursor<'txn, T>, end_bound: &Bound>, ) -> Result> { match end_bound { @@ -25,8 +25,8 @@ fn move_on_range_end<'txn>( } } -fn move_on_range_start<'txn>( - cursor: &mut RoCursor<'txn>, +fn move_on_range_start<'txn, T>( + cursor: &mut RoCursor<'txn, T>, start_bound: &mut Bound>, ) -> Result> { match start_bound { @@ -40,20 +40,20 @@ fn move_on_range_start<'txn>( } /// A read-only range iterator structure. -pub struct RoRange<'txn, KC, DC, C = DefaultComparator, IM = MoveThroughDuplicateValues> { - cursor: RoCursor<'txn>, +pub struct RoRange<'txn, T, KC, DC, C = DefaultComparator, IM = MoveThroughDuplicateValues> { + cursor: RoCursor<'txn, T>, move_on_start: bool, start_bound: Bound>, end_bound: Bound>, _phantom: marker::PhantomData<(KC, DC, C, IM)>, } -impl<'txn, KC, DC, C, IM> RoRange<'txn, KC, DC, C, IM> { +impl<'txn, T, KC, DC, C, IM> RoRange<'txn, T, KC, DC, C, IM> { pub(crate) fn new( - cursor: RoCursor<'txn>, + cursor: RoCursor<'txn, T>, start_bound: Bound>, end_bound: Bound>, - ) -> RoRange<'txn, KC, DC, C, IM> { + ) -> RoRange<'txn, T, KC, DC, C, IM> { RoRange { cursor, move_on_start: true, @@ -66,7 +66,7 @@ impl<'txn, KC, DC, C, IM> RoRange<'txn, KC, DC, C, IM> { /// Move on the first value of keys, ignoring duplicate values. /// /// For more info, see [`RoIter::move_between_keys`]. - pub fn move_between_keys(self) -> RoRange<'txn, KC, DC, C, MoveBetweenKeys> { + pub fn move_between_keys(self) -> RoRange<'txn, T, KC, DC, C, MoveBetweenKeys> { RoRange { cursor: self.cursor, move_on_start: self.move_on_start, @@ -81,7 +81,7 @@ impl<'txn, KC, DC, C, IM> RoRange<'txn, KC, DC, C, IM> { /// For more info, see [`RoIter::move_through_duplicate_values`]. pub fn move_through_duplicate_values( self, - ) -> RoRange<'txn, KC, DC, C, MoveThroughDuplicateValues> { + ) -> RoRange<'txn, T, KC, DC, C, MoveThroughDuplicateValues> { RoRange { cursor: self.cursor, move_on_start: self.move_on_start, @@ -92,7 +92,7 @@ impl<'txn, KC, DC, C, IM> RoRange<'txn, KC, DC, C, IM> { } /// Change the codec types of this iterator, specifying the codecs. - pub fn remap_types(self) -> RoRange<'txn, KC2, DC2, C, IM> { + pub fn remap_types(self) -> RoRange<'txn, T, KC2, DC2, C, IM> { RoRange { cursor: self.cursor, move_on_start: self.move_on_start, @@ -103,22 +103,22 @@ impl<'txn, KC, DC, C, IM> RoRange<'txn, KC, DC, C, IM> { } /// Change the key codec type of this iterator, specifying the new codec. - pub fn remap_key_type(self) -> RoRange<'txn, KC2, DC, C, IM> { + pub fn remap_key_type(self) -> RoRange<'txn, T, KC2, DC, C, IM> { self.remap_types::() } /// Change the data codec type of this iterator, specifying the new codec. - pub fn remap_data_type(self) -> RoRange<'txn, KC, DC2, C, IM> { + pub fn remap_data_type(self) -> RoRange<'txn, T, KC, DC2, C, IM> { self.remap_types::() } /// Wrap the data bytes into a lazy decoder. - pub fn lazily_decode_data(self) -> RoRange<'txn, KC, LazyDecode, C, IM> { + pub fn lazily_decode_data(self) -> RoRange<'txn, T, KC, LazyDecode, C, IM> { self.remap_types::>() } } -impl<'txn, KC, DC, C, IM> Iterator for RoRange<'txn, KC, DC, C, IM> +impl<'txn, T, KC, DC, C, IM> Iterator for RoRange<'txn, T, KC, DC, C, IM> where KC: BytesDecode<'txn>, DC: BytesDecode<'txn>, @@ -199,7 +199,8 @@ impl fmt::Debug for RoRange<'_, KC, DC, C, IM> { } } -unsafe impl Send for RoRange<'_, KC, DC, C, IM> {} +// Only implement Send if the transaction is Send (WithoutTls) +unsafe impl Send for RoRange<'_, WithoutTls, KC, DC, C, IM> {} /// A read-write range iterator structure. pub struct RwRange<'txn, KC, DC, C = DefaultComparator, IM = MoveThroughDuplicateValues> { @@ -476,20 +477,20 @@ impl fmt::Debug for RwRange<'_, KC, DC, C, IM> { } /// A reverse read-only range iterator structure. -pub struct RoRevRange<'txn, KC, DC, C = DefaultComparator, IM = MoveThroughDuplicateValues> { - cursor: RoCursor<'txn>, +pub struct RoRevRange<'txn, T, KC, DC, C = DefaultComparator, IM = MoveThroughDuplicateValues> { + cursor: RoCursor<'txn, T>, move_on_end: bool, start_bound: Bound>, end_bound: Bound>, _phantom: marker::PhantomData<(KC, DC, C, IM)>, } -impl<'txn, KC, DC, C, IM> RoRevRange<'txn, KC, DC, C, IM> { +impl<'txn, T, KC, DC, C, IM> RoRevRange<'txn, T, KC, DC, C, IM> { pub(crate) fn new( - cursor: RoCursor<'txn>, + cursor: RoCursor<'txn, T>, start_bound: Bound>, end_bound: Bound>, - ) -> RoRevRange<'txn, KC, DC, C, IM> { + ) -> RoRevRange<'txn, T, KC, DC, C, IM> { RoRevRange { cursor, move_on_end: true, @@ -502,7 +503,7 @@ impl<'txn, KC, DC, C, IM> RoRevRange<'txn, KC, DC, C, IM> { /// Move on the first value of keys, ignoring duplicate values. /// /// For more info, see [`RoIter::move_between_keys`]. - pub fn move_between_keys(self) -> RoRevRange<'txn, KC, DC, C, MoveBetweenKeys> { + pub fn move_between_keys(self) -> RoRevRange<'txn, T, KC, DC, C, MoveBetweenKeys> { RoRevRange { cursor: self.cursor, move_on_end: self.move_on_end, @@ -517,7 +518,7 @@ impl<'txn, KC, DC, C, IM> RoRevRange<'txn, KC, DC, C, IM> { /// For more info, see [`RoIter::move_through_duplicate_values`]. pub fn move_through_duplicate_values( self, - ) -> RoRevRange<'txn, KC, DC, C, MoveThroughDuplicateValues> { + ) -> RoRevRange<'txn, T, KC, DC, C, MoveThroughDuplicateValues> { RoRevRange { cursor: self.cursor, move_on_end: self.move_on_end, @@ -528,7 +529,7 @@ impl<'txn, KC, DC, C, IM> RoRevRange<'txn, KC, DC, C, IM> { } /// Change the codec types of this iterator, specifying the codecs. - pub fn remap_types(self) -> RoRevRange<'txn, KC2, DC2, C, IM> { + pub fn remap_types(self) -> RoRevRange<'txn, T, KC2, DC2, C, IM> { RoRevRange { cursor: self.cursor, move_on_end: self.move_on_end, @@ -539,22 +540,22 @@ impl<'txn, KC, DC, C, IM> RoRevRange<'txn, KC, DC, C, IM> { } /// Change the key codec type of this iterator, specifying the new codec. - pub fn remap_key_type(self) -> RoRevRange<'txn, KC2, DC, C, IM> { + pub fn remap_key_type(self) -> RoRevRange<'txn, T, KC2, DC, C, IM> { self.remap_types::() } /// Change the data codec type of this iterator, specifying the new codec. - pub fn remap_data_type(self) -> RoRevRange<'txn, KC, DC2, C, IM> { + pub fn remap_data_type(self) -> RoRevRange<'txn, T, KC, DC2, C, IM> { self.remap_types::() } /// Wrap the data bytes into a lazy decoder. - pub fn lazily_decode_data(self) -> RoRevRange<'txn, KC, LazyDecode, C, IM> { + pub fn lazily_decode_data(self) -> RoRevRange<'txn, T, KC, LazyDecode, C, IM> { self.remap_types::>() } } -impl<'txn, KC, DC, C, IM> Iterator for RoRevRange<'txn, KC, DC, C, IM> +impl<'txn, T, KC, DC, C, IM> Iterator for RoRevRange<'txn, T, KC, DC, C, IM> where KC: BytesDecode<'txn>, DC: BytesDecode<'txn>, @@ -637,7 +638,8 @@ impl fmt::Debug for RoRevRange<'_, KC, DC, C, IM> { } } -unsafe impl Send for RoRevRange<'_, KC, DC, C, IM> {} +// Only implement Send if the transaction is Send (WithoutTls) +unsafe impl Send for RoRevRange<'_, WithoutTls, KC, DC, C, IM> {} /// A reverse read-write range iterator structure. pub struct RwRevRange<'txn, KC, DC, C = DefaultComparator, IM = MoveThroughDuplicateValues> {