aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2022-06-06 15:04:04 +0200
committerAlex Auvolat <alex@adnab.me>2022-06-06 15:07:37 +0200
commita65049db8fbd373382f8ff73ef7a1c07c3df10e0 (patch)
treee256dc5292b6235f04bdaa95af2ff56f48457fc4 /src
parent17918e2ef5dec8d131c4242111688b2a2e96aade (diff)
downloadgarage-a65049db8fbd373382f8ff73ef7a1c07c3df10e0.tar.gz
garage-a65049db8fbd373382f8ff73ef7a1c07c3df10e0.zip
Simplify lmdb adapter (one less indirection)
Diffstat (limited to 'src')
-rw-r--r--src/db/lmdb_adapter.rs33
1 files changed, 6 insertions, 27 deletions
diff --git a/src/db/lmdb_adapter.rs b/src/db/lmdb_adapter.rs
index 04902d7f..9173ad37 100644
--- a/src/db/lmdb_adapter.rs
+++ b/src/db/lmdb_adapter.rs
@@ -1,6 +1,4 @@
-use core::marker::PhantomPinned;
use core::ops::Bound;
-use core::pin::Pin;
use core::ptr::NonNull;
use std::collections::HashMap;
@@ -272,7 +270,6 @@ where
{
tx: RoTxn<'a>,
iter: Option<I>,
- _pin: PhantomPinned,
}
impl<'a, I> TxAndIterator<'a, I>
@@ -283,22 +280,12 @@ where
where
F: FnOnce(&'a RoTxn<'a>) -> Result<I>,
{
- let res = TxAndIterator {
- tx,
- iter: None,
- _pin: PhantomPinned,
- };
- let mut boxed = Box::pin(res);
-
- unsafe {
- let tx = NonNull::from(&boxed.tx);
- let iter = iterfun(tx.as_ref())?;
+ let mut res = TxAndIterator { tx, iter: None };
- let mut_ref: Pin<&mut TxAndIterator<'a, I>> = Pin::as_mut(&mut boxed);
- Pin::get_unchecked_mut(mut_ref).iter = Some(iter);
- }
+ let tx = unsafe { NonNull::from(&res.tx).as_ref() };
+ res.iter = Some(iterfun(tx)?);
- Ok(Box::new(TxAndIteratorPin(boxed)))
+ Ok(Box::new(res))
}
}
@@ -311,22 +298,14 @@ where
}
}
-struct TxAndIteratorPin<'a, I: Iterator<Item = IteratorItem<'a>> + 'a>(
- Pin<Box<TxAndIterator<'a, I>>>,
-);
-
-impl<'a, I> Iterator for TxAndIteratorPin<'a, I>
+impl<'a, I> Iterator for TxAndIterator<'a, I>
where
I: Iterator<Item = IteratorItem<'a>> + 'a,
{
type Item = Result<(Value, Value)>;
fn next(&mut self) -> Option<Self::Item> {
- let iter_ref = unsafe {
- let mut_ref: Pin<&mut TxAndIterator<'a, I>> = Pin::as_mut(&mut self.0);
- Pin::get_unchecked_mut(mut_ref).iter.as_mut()
- };
- match iter_ref.unwrap().next() {
+ match self.iter.as_mut().unwrap().next() {
None => None,
Some(Err(e)) => Some(Err(e.into())),
Some(Ok((k, v))) => Some(Ok((k.to_vec(), v.to_vec()))),