Add into_owned for obtaining a 'static transaction
This commit is contained in:
parent
cddcb52750
commit
3f9f0904c2
15
src/lib.rs
15
src/lib.rs
|
@ -1,4 +1,5 @@
|
|||
use persy::{Config, IndexId, IndexType, Persy, PersyError, SegmentId, TxIndexIter, ValueMode, PE};
|
||||
use std::borrow::Cow;
|
||||
use std::marker::PhantomData;
|
||||
use std::ops::RangeBounds;
|
||||
use std::path::Path;
|
||||
|
@ -30,7 +31,7 @@ pub struct Tree<K, V> {
|
|||
}
|
||||
|
||||
pub struct Transaction<'a, K, V> {
|
||||
tree: &'a Tree<K, V>,
|
||||
tree: Cow<'a, Tree<K, V>>,
|
||||
tx: persy::Transaction,
|
||||
}
|
||||
|
||||
|
@ -91,7 +92,10 @@ impl<K, V> Tree<K, V> {
|
|||
pub fn transaction(&self) -> Result<Transaction<'_, K, V>, Error> {
|
||||
let tx = self.persy.begin()?;
|
||||
|
||||
Ok(Transaction { tree: self, tx })
|
||||
Ok(Transaction {
|
||||
tree: Cow::Borrowed(self),
|
||||
tx,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -127,6 +131,13 @@ where
|
|||
self.tx.rollback()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn into_owned(self) -> Transaction<'static, K, V> {
|
||||
Transaction {
|
||||
tree: Cow::Owned(self.tree.into_owned()),
|
||||
tx: self.tx,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, K, V> Iter<'a, K, V>
|
||||
|
|
Loading…
Reference in a new issue