Correct error type for (unimplemented) iterators in transactions
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/pr Build is failing

This commit is contained in:
Alex 2022-06-07 17:56:11 +02:00
parent 0543cb3453
commit c103ca8bf2
Signed by: lx
GPG key ID: 0E496D15096376BE
4 changed files with 24 additions and 23 deletions

View file

@ -25,6 +25,7 @@ pub struct Tree(Arc<dyn IDb>, usize);
pub type Value = Vec<u8>; pub type Value = Vec<u8>;
pub type ValueIter<'a> = Box<dyn std::iter::Iterator<Item = Result<(Value, Value)>> + 'a>; pub type ValueIter<'a> = Box<dyn std::iter::Iterator<Item = Result<(Value, Value)>> + 'a>;
pub type TxValueIter<'a> = Box<dyn std::iter::Iterator<Item = TxOpResult<(Value, Value)>> + 'a>;
// ---- // ----
@ -251,16 +252,16 @@ impl<'a> Transaction<'a> {
} }
#[inline] #[inline]
pub fn iter(&self, tree: &Tree) -> TxOpResult<ValueIter<'_>> { pub fn iter(&self, tree: &Tree) -> TxOpResult<TxValueIter<'_>> {
self.0.iter(tree.1) self.0.iter(tree.1)
} }
#[inline] #[inline]
pub fn iter_rev(&self, tree: &Tree) -> TxOpResult<ValueIter<'_>> { pub fn iter_rev(&self, tree: &Tree) -> TxOpResult<TxValueIter<'_>> {
self.0.iter_rev(tree.1) self.0.iter_rev(tree.1)
} }
#[inline] #[inline]
pub fn range<K, R>(&self, tree: &Tree, range: R) -> TxOpResult<ValueIter<'_>> pub fn range<K, R>(&self, tree: &Tree, range: R) -> TxOpResult<TxValueIter<'_>>
where where
K: AsRef<[u8]>, K: AsRef<[u8]>,
R: RangeBounds<K>, R: RangeBounds<K>,
@ -270,7 +271,7 @@ impl<'a> Transaction<'a> {
self.0.range(tree.1, get_bound(sb), get_bound(eb)) self.0.range(tree.1, get_bound(sb), get_bound(eb))
} }
#[inline] #[inline]
pub fn range_rev<K, R>(&self, tree: &Tree, range: R) -> TxOpResult<ValueIter<'_>> pub fn range_rev<K, R>(&self, tree: &Tree, range: R) -> TxOpResult<TxValueIter<'_>>
where where
K: AsRef<[u8]>, K: AsRef<[u8]>,
R: RangeBounds<K>, R: RangeBounds<K>,
@ -331,21 +332,21 @@ pub(crate) trait ITx {
fn insert(&mut self, tree: usize, key: &[u8], value: &[u8]) -> TxOpResult<Option<Value>>; fn insert(&mut self, tree: usize, key: &[u8], value: &[u8]) -> TxOpResult<Option<Value>>;
fn remove(&mut self, tree: usize, key: &[u8]) -> TxOpResult<Option<Value>>; fn remove(&mut self, tree: usize, key: &[u8]) -> TxOpResult<Option<Value>>;
fn iter(&self, tree: usize) -> TxOpResult<ValueIter<'_>>; fn iter(&self, tree: usize) -> TxOpResult<TxValueIter<'_>>;
fn iter_rev(&self, tree: usize) -> TxOpResult<ValueIter<'_>>; fn iter_rev(&self, tree: usize) -> TxOpResult<TxValueIter<'_>>;
fn range<'r>( fn range<'r>(
&self, &self,
tree: usize, tree: usize,
low: Bound<&'r [u8]>, low: Bound<&'r [u8]>,
high: Bound<&'r [u8]>, high: Bound<&'r [u8]>,
) -> TxOpResult<ValueIter<'_>>; ) -> TxOpResult<TxValueIter<'_>>;
fn range_rev<'r>( fn range_rev<'r>(
&self, &self,
tree: usize, tree: usize,
low: Bound<&'r [u8]>, low: Bound<&'r [u8]>,
high: Bound<&'r [u8]>, high: Bound<&'r [u8]>,
) -> TxOpResult<ValueIter<'_>>; ) -> TxOpResult<TxValueIter<'_>>;
} }
pub(crate) trait ITxFn { pub(crate) trait ITxFn {

View file

@ -10,7 +10,7 @@ use heed::{BytesDecode, Env, RoTxn, RwTxn, UntypedDatabase as Database};
use crate::{ use crate::{
Db, Error, IDb, ITx, ITxFn, Result, TxError, TxFnResult, TxOpError, TxOpResult, TxResult, Db, Error, IDb, ITx, ITxFn, Result, TxError, TxFnResult, TxOpError, TxOpResult, TxResult,
Value, ValueIter, Value, ValueIter, TxValueIter
}; };
pub use heed; pub use heed;
@ -243,10 +243,10 @@ impl<'a, 'db> ITx for LmdbTx<'a, 'db> {
Ok(old_val) Ok(old_val)
} }
fn iter(&self, _tree: usize) -> TxOpResult<ValueIter<'_>> { fn iter(&self, _tree: usize) -> TxOpResult<TxValueIter<'_>> {
unimplemented!("Iterators in transactions not supported with LMDB backend"); unimplemented!("Iterators in transactions not supported with LMDB backend");
} }
fn iter_rev(&self, _tree: usize) -> TxOpResult<ValueIter<'_>> { fn iter_rev(&self, _tree: usize) -> TxOpResult<TxValueIter<'_>> {
unimplemented!("Iterators in transactions not supported with LMDB backend"); unimplemented!("Iterators in transactions not supported with LMDB backend");
} }
@ -255,7 +255,7 @@ impl<'a, 'db> ITx for LmdbTx<'a, 'db> {
_tree: usize, _tree: usize,
_low: Bound<&'r [u8]>, _low: Bound<&'r [u8]>,
_high: Bound<&'r [u8]>, _high: Bound<&'r [u8]>,
) -> TxOpResult<ValueIter<'_>> { ) -> TxOpResult<TxValueIter<'_>> {
unimplemented!("Iterators in transactions not supported with LMDB backend"); unimplemented!("Iterators in transactions not supported with LMDB backend");
} }
fn range_rev<'r>( fn range_rev<'r>(
@ -263,7 +263,7 @@ impl<'a, 'db> ITx for LmdbTx<'a, 'db> {
_tree: usize, _tree: usize,
_low: Bound<&'r [u8]>, _low: Bound<&'r [u8]>,
_high: Bound<&'r [u8]>, _high: Bound<&'r [u8]>,
) -> TxOpResult<ValueIter<'_>> { ) -> TxOpResult<TxValueIter<'_>> {
unimplemented!("Iterators in transactions not supported with LMDB backend"); unimplemented!("Iterators in transactions not supported with LMDB backend");
} }
} }

View file

@ -11,7 +11,7 @@ use sled::transaction::{
use crate::{ use crate::{
Db, Error, IDb, ITx, ITxFn, Result, TxError, TxFnResult, TxOpError, TxOpResult, TxResult, Db, Error, IDb, ITx, ITxFn, Result, TxError, TxFnResult, TxOpError, TxOpResult, TxResult,
Value, ValueIter, Value, ValueIter, TxValueIter
}; };
pub use sled; pub use sled;
@ -230,10 +230,10 @@ impl<'a> ITx for SledTx<'a> {
Ok(old_val.map(|x| x.to_vec())) Ok(old_val.map(|x| x.to_vec()))
} }
fn iter(&self, _tree: usize) -> TxOpResult<ValueIter<'_>> { fn iter(&self, _tree: usize) -> TxOpResult<TxValueIter<'_>> {
unimplemented!("Iterators in transactions not supported with Sled backend"); unimplemented!("Iterators in transactions not supported with Sled backend");
} }
fn iter_rev(&self, _tree: usize) -> TxOpResult<ValueIter<'_>> { fn iter_rev(&self, _tree: usize) -> TxOpResult<TxValueIter<'_>> {
unimplemented!("Iterators in transactions not supported with Sled backend"); unimplemented!("Iterators in transactions not supported with Sled backend");
} }
@ -242,7 +242,7 @@ impl<'a> ITx for SledTx<'a> {
_tree: usize, _tree: usize,
_low: Bound<&'r [u8]>, _low: Bound<&'r [u8]>,
_high: Bound<&'r [u8]>, _high: Bound<&'r [u8]>,
) -> TxOpResult<ValueIter<'_>> { ) -> TxOpResult<TxValueIter<'_>> {
unimplemented!("Iterators in transactions not supported with Sled backend"); unimplemented!("Iterators in transactions not supported with Sled backend");
} }
fn range_rev<'r>( fn range_rev<'r>(
@ -250,7 +250,7 @@ impl<'a> ITx for SledTx<'a> {
_tree: usize, _tree: usize,
_low: Bound<&'r [u8]>, _low: Bound<&'r [u8]>,
_high: Bound<&'r [u8]>, _high: Bound<&'r [u8]>,
) -> TxOpResult<ValueIter<'_>> { ) -> TxOpResult<TxValueIter<'_>> {
unimplemented!("Iterators in transactions not supported with Sled backend"); unimplemented!("Iterators in transactions not supported with Sled backend");
} }
} }

View file

@ -12,7 +12,7 @@ use rusqlite::{params, Connection, Rows, Statement, Transaction};
use crate::{ use crate::{
Db, Error, IDb, ITx, ITxFn, Result, TxError, TxFnResult, TxOpError, TxOpResult, TxResult, Db, Error, IDb, ITx, ITxFn, Result, TxError, TxFnResult, TxOpError, TxOpResult, TxResult,
Value, ValueIter, Value, ValueIter, TxValueIter
}; };
pub use rusqlite; pub use rusqlite;
@ -372,10 +372,10 @@ impl<'a> ITx for SqliteTx<'a> {
Ok(old_val) Ok(old_val)
} }
fn iter(&self, _tree: usize) -> TxOpResult<ValueIter<'_>> { fn iter(&self, _tree: usize) -> TxOpResult<TxValueIter<'_>> {
unimplemented!(); unimplemented!();
} }
fn iter_rev(&self, _tree: usize) -> TxOpResult<ValueIter<'_>> { fn iter_rev(&self, _tree: usize) -> TxOpResult<TxValueIter<'_>> {
unimplemented!(); unimplemented!();
} }
@ -384,7 +384,7 @@ impl<'a> ITx for SqliteTx<'a> {
_tree: usize, _tree: usize,
_low: Bound<&'r [u8]>, _low: Bound<&'r [u8]>,
_high: Bound<&'r [u8]>, _high: Bound<&'r [u8]>,
) -> TxOpResult<ValueIter<'_>> { ) -> TxOpResult<TxValueIter<'_>> {
unimplemented!(); unimplemented!();
} }
fn range_rev<'r>( fn range_rev<'r>(
@ -392,7 +392,7 @@ impl<'a> ITx for SqliteTx<'a> {
_tree: usize, _tree: usize,
_low: Bound<&'r [u8]>, _low: Bound<&'r [u8]>,
_high: Bound<&'r [u8]>, _high: Bound<&'r [u8]>,
) -> TxOpResult<ValueIter<'_>> { ) -> TxOpResult<TxValueIter<'_>> {
unimplemented!(); unimplemented!();
} }
} }