Rename confusingly or inappropriately named lifetimes

Signed-off-by: Victor Porof <victor.porof@gmail.com>
without.crypto
Victor Porof 5 years ago
parent 6a866fdad2
commit c8fac3bb43
  1. 4
      examples/simple-store.rs
  2. 12
      src/backend/impl_lmdb/cursor.rs
  3. 12
      src/backend/impl_lmdb/environment.rs
  4. 12
      src/backend/impl_lmdb/iter.rs
  5. 20
      src/backend/impl_lmdb/transaction.rs
  6. 12
      src/backend/impl_safe/cursor.rs
  7. 12
      src/backend/impl_safe/environment.rs
  8. 6
      src/backend/impl_safe/iter.rs
  9. 32
      src/backend/impl_safe/transaction.rs
  10. 34
      src/backend/traits.rs
  11. 36
      src/env.rs
  12. 24
      src/readwrite.rs
  13. 4
      src/store/integer.rs
  14. 12
      src/store/integermulti.rs
  15. 22
      src/store/multi.rs
  16. 30
      src/store/single.rs
  17. 20
      src/value.rs
  18. 8
      tests/test_txn.rs

@ -26,9 +26,9 @@ use rkv::{
};
type MultiStore = rkv::MultiStore<LmdbDatabase>;
type Writer<'env> = rkv::Writer<LmdbRwTransaction<'env>>;
type Writer<'w> = rkv::Writer<LmdbRwTransaction<'w>>;
fn getput<'env, 's>(store: MultiStore, writer: &'env mut Writer, ids: &'s mut Vec<String>) {
fn getput<'w, 's>(store: MultiStore, writer: &'w mut Writer, ids: &'s mut Vec<String>) {
let keys = vec!["str1", "str2", "str3"];
// we convert the writer into a cursor so that we can safely read
for k in keys.iter() {

@ -14,10 +14,10 @@ use super::IterImpl;
use crate::backend::traits::BackendRoCursor;
#[derive(Debug)]
pub struct RoCursorImpl<'env>(pub(crate) lmdb::RoCursor<'env>);
pub struct RoCursorImpl<'c>(pub(crate) lmdb::RoCursor<'c>);
impl<'env> BackendRoCursor<'env> for RoCursorImpl<'env> {
type Iter = IterImpl<'env, lmdb::RoCursor<'env>>;
impl<'c> BackendRoCursor<'c> for RoCursorImpl<'c> {
type Iter = IterImpl<'c, lmdb::RoCursor<'c>>;
fn into_iter(self) -> Self::Iter {
// We call RoCursor.iter() instead of RoCursor.iter_start() because
@ -44,10 +44,10 @@ impl<'env> BackendRoCursor<'env> for RoCursorImpl<'env> {
}
#[derive(Debug)]
pub struct RwCursorImpl<'env>(pub(crate) lmdb::RwCursor<'env>);
pub struct RwCursorImpl<'c>(pub(crate) lmdb::RwCursor<'c>);
impl<'env> BackendRoCursor<'env> for RwCursorImpl<'env> {
type Iter = IterImpl<'env, lmdb::RwCursor<'env>>;
impl<'c> BackendRoCursor<'c> for RwCursorImpl<'c> {
type Iter = IterImpl<'c, lmdb::RwCursor<'c>>;
fn into_iter(self) -> Self::Iter {
IterImpl::new(self.0, lmdb::RwCursor::iter)

@ -28,7 +28,7 @@ use crate::backend::traits::{
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
pub struct EnvironmentBuilderImpl(lmdb::EnvironmentBuilder);
impl<'env> BackendEnvironmentBuilder<'env> for EnvironmentBuilderImpl {
impl<'b> BackendEnvironmentBuilder<'b> for EnvironmentBuilderImpl {
type Error = ErrorImpl;
type Environment = EnvironmentImpl;
type Flags = EnvironmentFlagsImpl;
@ -68,14 +68,14 @@ impl<'env> BackendEnvironmentBuilder<'env> for EnvironmentBuilderImpl {
#[derive(Debug)]
pub struct EnvironmentImpl(lmdb::Environment);
impl<'env> BackendEnvironment<'env> for EnvironmentImpl {
impl<'e> BackendEnvironment<'e> for EnvironmentImpl {
type Error = ErrorImpl;
type Database = DatabaseImpl;
type Flags = DatabaseFlagsImpl;
type Stat = StatImpl;
type Info = InfoImpl;
type RoTransaction = RoTransactionImpl<'env>;
type RwTransaction = RwTransactionImpl<'env>;
type RoTransaction = RoTransactionImpl<'e>;
type RwTransaction = RwTransactionImpl<'e>;
fn open_db(&self, name: Option<&str>) -> Result<Self::Database, Self::Error> {
self.0.open_db(name).map(DatabaseImpl).map_err(ErrorImpl)
@ -85,11 +85,11 @@ impl<'env> BackendEnvironment<'env> for EnvironmentImpl {
self.0.create_db(name, flags.0).map(DatabaseImpl).map_err(ErrorImpl)
}
fn begin_ro_txn(&'env self) -> Result<Self::RoTransaction, Self::Error> {
fn begin_ro_txn(&'e self) -> Result<Self::RoTransaction, Self::Error> {
self.0.begin_ro_txn().map(RoTransactionImpl).map_err(ErrorImpl)
}
fn begin_rw_txn(&'env self) -> Result<Self::RwTransaction, Self::Error> {
fn begin_rw_txn(&'e self) -> Result<Self::RwTransaction, Self::Error> {
self.0.begin_rw_txn().map(RwTransactionImpl).map_err(ErrorImpl)
}

@ -11,18 +11,18 @@
use super::ErrorImpl;
use crate::backend::traits::BackendIter;
pub struct IterImpl<'env, C> {
pub struct IterImpl<'i, C> {
// LMDB semantics dictate that a cursor must be valid for the entire lifetime
// of an iterator. In other words, cursors must not be dropped while an
// iterator built from it is alive. Unfortunately, the LMDB crate API does
// not express this through the type system, so we must enforce it somehow.
#[allow(dead_code)]
cursor: C,
iter: lmdb::Iter<'env>,
iter: lmdb::Iter<'i>,
}
impl<'env, C> IterImpl<'env, C> {
pub(crate) fn new(mut cursor: C, to_iter: impl FnOnce(&mut C) -> lmdb::Iter<'env>) -> IterImpl<'env, C> {
impl<'i, C> IterImpl<'i, C> {
pub(crate) fn new(mut cursor: C, to_iter: impl FnOnce(&mut C) -> lmdb::Iter<'i>) -> IterImpl<'i, C> {
let iter = to_iter(&mut cursor);
IterImpl {
cursor,
@ -31,11 +31,11 @@ impl<'env, C> IterImpl<'env, C> {
}
}
impl<'env, C> BackendIter<'env> for IterImpl<'env, C> {
impl<'i, C> BackendIter<'i> for IterImpl<'i, C> {
type Error = ErrorImpl;
#[allow(clippy::type_complexity)]
fn next(&mut self) -> Option<Result<(&'env [u8], &'env [u8]), Self::Error>> {
fn next(&mut self) -> Option<Result<(&'i [u8], &'i [u8]), Self::Error>> {
self.iter.next().map(|e| e.map_err(ErrorImpl))
}
}

@ -24,9 +24,9 @@ use crate::backend::traits::{
};
#[derive(Debug)]
pub struct RoTransactionImpl<'env>(pub(crate) lmdb::RoTransaction<'env>);
pub struct RoTransactionImpl<'t>(pub(crate) lmdb::RoTransaction<'t>);
impl<'env> BackendRoTransaction for RoTransactionImpl<'env> {
impl<'t> BackendRoTransaction for RoTransactionImpl<'t> {
type Error = ErrorImpl;
type Database = DatabaseImpl;
@ -39,18 +39,18 @@ impl<'env> BackendRoTransaction for RoTransactionImpl<'env> {
}
}
impl<'env> BackendRoCursorTransaction<'env> for RoTransactionImpl<'env> {
type RoCursor = RoCursorImpl<'env>;
impl<'t> BackendRoCursorTransaction<'t> for RoTransactionImpl<'t> {
type RoCursor = RoCursorImpl<'t>;
fn open_ro_cursor(&'env self, db: &Self::Database) -> Result<Self::RoCursor, Self::Error> {
fn open_ro_cursor(&'t self, db: &Self::Database) -> Result<Self::RoCursor, Self::Error> {
self.0.open_ro_cursor(db.0).map(RoCursorImpl).map_err(ErrorImpl)
}
}
#[derive(Debug)]
pub struct RwTransactionImpl<'env>(pub(crate) lmdb::RwTransaction<'env>);
pub struct RwTransactionImpl<'t>(pub(crate) lmdb::RwTransaction<'t>);
impl<'env> BackendRwTransaction for RwTransactionImpl<'env> {
impl<'t> BackendRwTransaction for RwTransactionImpl<'t> {
type Error = ErrorImpl;
type Database = DatabaseImpl;
type Flags = WriteFlagsImpl;
@ -86,10 +86,10 @@ impl<'env> BackendRwTransaction for RwTransactionImpl<'env> {
}
}
impl<'env> BackendRwCursorTransaction<'env> for RwTransactionImpl<'env> {
type RoCursor = RoCursorImpl<'env>;
impl<'t> BackendRwCursorTransaction<'t> for RwTransactionImpl<'t> {
type RoCursor = RoCursorImpl<'t>;
fn open_ro_cursor(&'env self, db: &Self::Database) -> Result<Self::RoCursor, Self::Error> {
fn open_ro_cursor(&'t self, db: &Self::Database) -> Result<Self::RoCursor, Self::Error> {
self.0.open_ro_cursor(db.0).map(RoCursorImpl).map_err(ErrorImpl)
}
}

@ -15,10 +15,10 @@ use super::{
use crate::backend::traits::BackendRoCursor;
#[derive(Debug)]
pub struct RoCursorImpl<'env>(pub(crate) &'env Snapshot);
pub struct RoCursorImpl<'c>(pub(crate) &'c Snapshot);
impl<'env> BackendRoCursor<'env> for RoCursorImpl<'env> {
type Iter = IterImpl<'env>;
impl<'c> BackendRoCursor<'c> for RoCursorImpl<'c> {
type Iter = IterImpl<'c>;
fn into_iter(self) -> Self::Iter {
IterImpl(Box::new(self.0.iter()))
@ -44,10 +44,10 @@ impl<'env> BackendRoCursor<'env> for RoCursorImpl<'env> {
}
#[derive(Debug)]
pub struct RwCursorImpl<'env>(&'env mut Snapshot);
pub struct RwCursorImpl<'c>(&'c mut Snapshot);
impl<'env> BackendRoCursor<'env> for RwCursorImpl<'env> {
type Iter = IterImpl<'env>;
impl<'c> BackendRoCursor<'c> for RwCursorImpl<'c> {
type Iter = IterImpl<'c>;
fn into_iter(self) -> Self::Iter {
unimplemented!()

@ -54,7 +54,7 @@ pub struct EnvironmentBuilderImpl {
map_size: Option<usize>,
}
impl<'env> BackendEnvironmentBuilder<'env> for EnvironmentBuilderImpl {
impl<'b> BackendEnvironmentBuilder<'b> for EnvironmentBuilderImpl {
type Error = ErrorImpl;
type Environment = EnvironmentImpl;
type Flags = EnvironmentFlagsImpl;
@ -187,14 +187,14 @@ impl EnvironmentImpl {
}
}
impl<'env> BackendEnvironment<'env> for EnvironmentImpl {
impl<'e> BackendEnvironment<'e> for EnvironmentImpl {
type Error = ErrorImpl;
type Database = DatabaseId;
type Flags = DatabaseFlagsImpl;
type Stat = StatImpl;
type Info = InfoImpl;
type RoTransaction = RoTransactionImpl<'env>;
type RwTransaction = RwTransactionImpl<'env>;
type RoTransaction = RoTransactionImpl<'e>;
type RwTransaction = RwTransactionImpl<'e>;
fn open_db(&self, name: Option<&str>) -> Result<Self::Database, Self::Error> {
if Arc::strong_count(&self.ro_txns) > 1 {
@ -219,11 +219,11 @@ impl<'env> BackendEnvironment<'env> for EnvironmentImpl {
Ok(*id)
}
fn begin_ro_txn(&'env self) -> Result<Self::RoTransaction, Self::Error> {
fn begin_ro_txn(&'e self) -> Result<Self::RoTransaction, Self::Error> {
RoTransactionImpl::new(self, self.ro_txns.clone())
}
fn begin_rw_txn(&'env self) -> Result<Self::RwTransaction, Self::Error> {
fn begin_rw_txn(&'e self) -> Result<Self::RwTransaction, Self::Error> {
RwTransactionImpl::new(self, self.rw_txns.clone())
}

@ -12,13 +12,13 @@ use super::ErrorImpl;
use crate::backend::traits::BackendIter;
// FIXME: Use generics instead.
pub struct IterImpl<'env>(pub(crate) Box<dyn Iterator<Item = (&'env [u8], &'env [u8])> + 'env>);
pub struct IterImpl<'i>(pub(crate) Box<dyn Iterator<Item = (&'i [u8], &'i [u8])> + 'i>);
impl<'env> BackendIter<'env> for IterImpl<'env> {
impl<'i> BackendIter<'i> for IterImpl<'i> {
type Error = ErrorImpl;
#[allow(clippy::type_complexity)]
fn next(&mut self) -> Option<Result<(&'env [u8], &'env [u8]), Self::Error>> {
fn next(&mut self) -> Option<Result<(&'i [u8], &'i [u8]), Self::Error>> {
self.0.next().map(Ok)
}
}

@ -27,14 +27,14 @@ use crate::backend::traits::{
};
#[derive(Debug)]
pub struct RoTransactionImpl<'env> {
env: &'env EnvironmentImpl,
pub struct RoTransactionImpl<'t> {
env: &'t EnvironmentImpl,
snapshots: HashMap<DatabaseId, Snapshot>,
idx: Arc<()>,
}
impl<'env> RoTransactionImpl<'env> {
pub(crate) fn new(env: &'env EnvironmentImpl, idx: Arc<()>) -> Result<RoTransactionImpl<'env>, ErrorImpl> {
impl<'t> RoTransactionImpl<'t> {
pub(crate) fn new(env: &'t EnvironmentImpl, idx: Arc<()>) -> Result<RoTransactionImpl<'t>, ErrorImpl> {
let snapshots = env.dbs()?.iter().map(|(id, db)| (id, db.snapshot())).collect();
Ok(RoTransactionImpl {
env,
@ -44,7 +44,7 @@ impl<'env> RoTransactionImpl<'env> {
}
}
impl<'env> BackendRoTransaction for RoTransactionImpl<'env> {
impl<'t> BackendRoTransaction for RoTransactionImpl<'t> {
type Error = ErrorImpl;
type Database = DatabaseId;
@ -58,24 +58,24 @@ impl<'env> BackendRoTransaction for RoTransactionImpl<'env> {
}
}
impl<'env> BackendRoCursorTransaction<'env> for RoTransactionImpl<'env> {
type RoCursor = RoCursorImpl<'env>;
impl<'t> BackendRoCursorTransaction<'t> for RoTransactionImpl<'t> {
type RoCursor = RoCursorImpl<'t>;
fn open_ro_cursor(&'env self, db: &Self::Database) -> Result<Self::RoCursor, Self::Error> {
fn open_ro_cursor(&'t self, db: &Self::Database) -> Result<Self::RoCursor, Self::Error> {
let snapshot = self.snapshots.get(db).ok_or_else(|| ErrorImpl::DbIsForeignError)?;
Ok(RoCursorImpl(snapshot))
}
}
#[derive(Debug)]
pub struct RwTransactionImpl<'env> {
env: &'env EnvironmentImpl,
pub struct RwTransactionImpl<'t> {
env: &'t EnvironmentImpl,
snapshots: HashMap<DatabaseId, Snapshot>,
idx: Arc<()>,
}
impl<'env> RwTransactionImpl<'env> {
pub(crate) fn new(env: &'env EnvironmentImpl, idx: Arc<()>) -> Result<RwTransactionImpl<'env>, ErrorImpl> {
impl<'t> RwTransactionImpl<'t> {
pub(crate) fn new(env: &'t EnvironmentImpl, idx: Arc<()>) -> Result<RwTransactionImpl<'t>, ErrorImpl> {
let snapshots = env.dbs()?.iter().map(|(id, db)| (id, db.snapshot())).collect();
Ok(RwTransactionImpl {
env,
@ -85,7 +85,7 @@ impl<'env> RwTransactionImpl<'env> {
}
}
impl<'env> BackendRwTransaction for RwTransactionImpl<'env> {
impl<'t> BackendRwTransaction for RwTransactionImpl<'t> {
type Error = ErrorImpl;
type Database = DatabaseId;
type Flags = WriteFlagsImpl;
@ -155,10 +155,10 @@ impl<'env> BackendRwTransaction for RwTransactionImpl<'env> {
}
}
impl<'env> BackendRwCursorTransaction<'env> for RwTransactionImpl<'env> {
type RoCursor = RoCursorImpl<'env>;
impl<'t> BackendRwCursorTransaction<'t> for RwTransactionImpl<'t> {
type RoCursor = RoCursorImpl<'t>;
fn open_ro_cursor(&'env self, db: &Self::Database) -> Result<Self::RoCursor, Self::Error> {
fn open_ro_cursor(&'t self, db: &Self::Database) -> Result<Self::RoCursor, Self::Error> {
let snapshot = self.snapshots.get(db).ok_or_else(|| ErrorImpl::DbIsForeignError)?;
Ok(RoCursorImpl(snapshot))
}

@ -67,9 +67,9 @@ pub trait BackendInfo {
fn num_readers(&self) -> usize;
}
pub trait BackendEnvironmentBuilder<'env>: Debug + Eq + PartialEq + Copy + Clone {
pub trait BackendEnvironmentBuilder<'b>: Debug + Eq + PartialEq + Copy + Clone {
type Error: BackendError;
type Environment: BackendEnvironment<'env>;
type Environment: BackendEnvironment<'b>;
type Flags: BackendEnvironmentFlags;
fn new() -> Self;
@ -87,22 +87,22 @@ pub trait BackendEnvironmentBuilder<'env>: Debug + Eq + PartialEq + Copy + Clone
fn open(&self, path: &Path) -> Result<Self::Environment, Self::Error>;
}
pub trait BackendEnvironment<'env>: Debug {
pub trait BackendEnvironment<'e>: Debug {
type Error: BackendError;
type Database: BackendDatabase;
type Flags: BackendDatabaseFlags;
type Stat: BackendStat;
type Info: BackendInfo;
type RoTransaction: BackendRoCursorTransaction<'env, Database = Self::Database>;
type RwTransaction: BackendRwCursorTransaction<'env, Database = Self::Database>;
type RoTransaction: BackendRoCursorTransaction<'e, Database = Self::Database>;
type RwTransaction: BackendRwCursorTransaction<'e, Database = Self::Database>;
fn open_db(&self, name: Option<&str>) -> Result<Self::Database, Self::Error>;
fn create_db(&self, name: Option<&str>, flags: Self::Flags) -> Result<Self::Database, Self::Error>;
fn begin_ro_txn(&'env self) -> Result<Self::RoTransaction, Self::Error>;
fn begin_ro_txn(&'e self) -> Result<Self::RoTransaction, Self::Error>;
fn begin_rw_txn(&'env self) -> Result<Self::RwTransaction, Self::Error>;
fn begin_rw_txn(&'e self) -> Result<Self::RwTransaction, Self::Error>;
fn sync(&self, force: bool) -> Result<(), Self::Error>;
@ -146,20 +146,20 @@ pub trait BackendRwTransaction: Debug {
fn abort(self);
}
pub trait BackendRoCursorTransaction<'env>: BackendRoTransaction {
type RoCursor: BackendRoCursor<'env>;
pub trait BackendRoCursorTransaction<'t>: BackendRoTransaction {
type RoCursor: BackendRoCursor<'t>;
fn open_ro_cursor(&'env self, db: &Self::Database) -> Result<Self::RoCursor, Self::Error>;
fn open_ro_cursor(&'t self, db: &Self::Database) -> Result<Self::RoCursor, Self::Error>;
}
pub trait BackendRwCursorTransaction<'env>: BackendRwTransaction {
type RoCursor: BackendRoCursor<'env>;
pub trait BackendRwCursorTransaction<'t>: BackendRwTransaction {
type RoCursor: BackendRoCursor<'t>;
fn open_ro_cursor(&'env self, db: &Self::Database) -> Result<Self::RoCursor, Self::Error>;
fn open_ro_cursor(&'t self, db: &Self::Database) -> Result<Self::RoCursor, Self::Error>;
}
pub trait BackendRoCursor<'env>: Debug {
type Iter: BackendIter<'env>;
pub trait BackendRoCursor<'c>: Debug {
type Iter: BackendIter<'c>;
fn into_iter(self) -> Self::Iter;
@ -172,9 +172,9 @@ pub trait BackendRoCursor<'env>: Debug {
K: AsRef<[u8]>;
}
pub trait BackendIter<'env> {
pub trait BackendIter<'i> {
type Error: BackendError;
#[allow(clippy::type_complexity)]
fn next(&mut self) -> Option<Result<(&'env [u8], &'env [u8]), Self::Error>>;
fn next(&mut self) -> Option<Result<(&'i [u8], &'i [u8]), Self::Error>>;
}

@ -57,13 +57,13 @@ pub struct Rkv<E> {
}
/// Static methods.
impl<'env, E> Rkv<E>
impl<'e, E> Rkv<E>
where
E: BackendEnvironment<'env>,
E: BackendEnvironment<'e>,
{
pub fn environment_builder<B>() -> B
where
B: BackendEnvironmentBuilder<'env, Environment = E>,
B: BackendEnvironmentBuilder<'e, Environment = E>,
{
B::new()
}
@ -72,7 +72,7 @@ where
#[allow(clippy::new_ret_no_self)]
pub fn new<B>(path: &Path) -> Result<Rkv<E>, StoreError>
where
B: BackendEnvironmentBuilder<'env, Environment = E>,
B: BackendEnvironmentBuilder<'e, Environment = E>,
{
Rkv::with_capacity::<B>(path, DEFAULT_MAX_DBS)
}
@ -80,7 +80,7 @@ where
/// Return a new Rkv environment that supports the specified number of open databases.
pub fn with_capacity<B>(path: &Path, max_dbs: c_uint) -> Result<Rkv<E>, StoreError>
where
B: BackendEnvironmentBuilder<'env, Environment = E>,
B: BackendEnvironmentBuilder<'e, Environment = E>,
{
if !path.is_dir() {
return Err(StoreError::DirectoryDoesNotExistError(path.into()));
@ -96,7 +96,7 @@ where
/// Return a new Rkv environment from the provided builder.
pub fn from_builder<B>(path: &Path, builder: B) -> Result<Rkv<E>, StoreError>
where
B: BackendEnvironmentBuilder<'env, Environment = E>,
B: BackendEnvironmentBuilder<'e, Environment = E>,
{
if !path.is_dir() {
return Err(StoreError::DirectoryDoesNotExistError(path.into()));
@ -113,9 +113,9 @@ where
}
/// Store creation methods.
impl<'env, E> Rkv<E>
impl<'e, E> Rkv<E>
where
E: BackendEnvironment<'env>,
E: BackendEnvironment<'e>,
{
/// Create or Open an existing database in (&[u8] -> Single Value) mode.
/// Note: that create=true cannot be called concurrently with other operations
@ -203,17 +203,17 @@ where
}
/// Read and write accessors.
impl<'env, E> Rkv<E>
impl<'e, E> Rkv<E>
where
E: BackendEnvironment<'env>,
E: BackendEnvironment<'e>,
{
/// Create a read transaction. There can be multiple concurrent readers
/// for an environment, up to the maximum specified by LMDB (default 126),
/// and you can open readers while a write transaction is active.
pub fn read<T>(&'env self) -> Result<Reader<T>, StoreError>
pub fn read<T>(&'e self) -> Result<Reader<T>, StoreError>
where
E: BackendEnvironment<'env, RoTransaction = T>,
T: BackendRoCursorTransaction<'env, Database = E::Database>,
E: BackendEnvironment<'e, RoTransaction = T>,
T: BackendRoCursorTransaction<'e, Database = E::Database>,
{
Ok(Reader::new(self.env.begin_ro_txn().map_err(|e| e.into())?))
}
@ -221,19 +221,19 @@ where
/// Create a write transaction. There can be only one write transaction
/// active at any given time, so trying to create a second one will block
/// until the first is committed or aborted.
pub fn write<T>(&'env self) -> Result<Writer<T>, StoreError>
pub fn write<T>(&'e self) -> Result<Writer<T>, StoreError>
where
E: BackendEnvironment<'env, RwTransaction = T>,
T: BackendRwCursorTransaction<'env, Database = E::Database>,
E: BackendEnvironment<'e, RwTransaction = T>,
T: BackendRwCursorTransaction<'e, Database = E::Database>,
{
Ok(Writer::new(self.env.begin_rw_txn().map_err(|e| e.into())?))
}
}
/// Other environment methods.
impl<'env, E> Rkv<E>
impl<'e, E> Rkv<E>
where
E: BackendEnvironment<'env>,
E: BackendEnvironment<'e>,
{
/// Flush the data buffers to disk. This call is only useful, when the environment
/// was open with either `NO_SYNC`, `NO_META_SYNC` or `MAP_ASYNC` (see below).

@ -23,25 +23,25 @@ use crate::value::Value;
pub struct Reader<T>(T);
pub struct Writer<T>(T);
pub trait Readable<'env> {
pub trait Readable<'r> {
type Database: BackendDatabase;
type RoCursor: BackendRoCursor<'env>;
type RoCursor: BackendRoCursor<'r>;
fn get<K>(&'env self, db: &Self::Database, k: &K) -> Result<Option<Value<'env>>, StoreError>
fn get<K>(&'r self, db: &Self::Database, k: &K) -> Result<Option<Value<'r>>, StoreError>
where
K: AsRef<[u8]>;
fn open_ro_cursor(&'env self, db: &Self::Database) -> Result<Self::RoCursor, StoreError>;
fn open_ro_cursor(&'r self, db: &Self::Database) -> Result<Self::RoCursor, StoreError>;
}
impl<'env, T> Readable<'env> for Reader<T>
impl<'r, T> Readable<'r> for Reader<T>
where
T: BackendRoCursorTransaction<'env>,
T: BackendRoCursorTransaction<'r>,
{
type Database = T::Database;
type RoCursor = T::RoCursor;
fn get<K>(&'env self, db: &T::Database, k: &K) -> Result<Option<Value<'env>>, StoreError>
fn get<K>(&'r self, db: &T::Database, k: &K) -> Result<Option<Value<'r>>, StoreError>
where
K: AsRef<[u8]>,
{
@ -49,7 +49,7 @@ where
read_transform(bytes)
}
fn open_ro_cursor(&'env self, db: &T::Database) -> Result<T::RoCursor, StoreError> {
fn open_ro_cursor(&'r self, db: &T::Database) -> Result<T::RoCursor, StoreError> {
self.0.open_ro_cursor(db).map_err(|e| e.into())
}
}
@ -69,14 +69,14 @@ where
}
}
impl<'env, T> Readable<'env> for Writer<T>
impl<'r, T> Readable<'r> for Writer<T>
where
T: BackendRwCursorTransaction<'env>,
T: BackendRwCursorTransaction<'r>,
{
type Database = T::Database;
type RoCursor = T::RoCursor;
fn get<K>(&'env self, db: &T::Database, k: &K) -> Result<Option<Value<'env>>, StoreError>
fn get<K>(&'r self, db: &T::Database, k: &K) -> Result<Option<Value<'r>>, StoreError>
where
K: AsRef<[u8]>,
{
@ -84,7 +84,7 @@ where
read_transform(bytes)
}
fn open_ro_cursor(&'env self, db: &T::Database) -> Result<T::RoCursor, StoreError> {
fn open_ro_cursor(&'r self, db: &T::Database) -> Result<T::RoCursor, StoreError> {
self.0.open_ro_cursor(db).map_err(|e| e.into())
}
}

@ -46,9 +46,9 @@ where
}
}
pub fn get<'env, R>(&self, reader: &'env R, k: K) -> Result<Option<Value<'env>>, StoreError>
pub fn get<'r, R>(&self, reader: &'r R, k: K) -> Result<Option<Value<'r>>, StoreError>
where
R: Readable<'env, Database = D>,
R: Readable<'r, Database = D>,
{
self.inner.get(reader, Key::new(&k)?)
}

@ -51,18 +51,18 @@ where
}
}
pub fn get<'env, R, I, C>(&self, reader: &'env R, k: K) -> Result<Iter<'env, I>, StoreError>
pub fn get<'r, R, I, C>(&self, reader: &'r R, k: K) -> Result<Iter<'r, I>, StoreError>
where
R: Readable<'env, Database = D, RoCursor = C>,
I: BackendIter<'env>,
C: BackendRoCursor<'env, Iter = I>,
R: Readable<'r, Database = D, RoCursor = C>,
I: BackendIter<'r>,
C: BackendRoCursor<'r, Iter = I>,
{
self.inner.get(reader, Key::new(&k)?)
}
pub fn get_first<'env, R>(&self, reader: &'env R, k: K) -> Result<Option<Value<'env>>, StoreError>
pub fn get_first<'r, R>(&self, reader: &'r R, k: K) -> Result<Option<Value<'r>>, StoreError>
where
R: Readable<'env, Database = D>,
R: Readable<'r, Database = D>,
{
self.inner.get_first(reader, Key::new(&k)?)
}

@ -32,9 +32,9 @@ pub struct MultiStore<D> {
db: D,
}
pub struct Iter<'env, I> {
pub struct Iter<'i, I> {
iter: I,
phantom: PhantomData<&'env ()>,
phantom: PhantomData<&'i ()>,
}
impl<D> MultiStore<D>
@ -48,11 +48,11 @@ where
}
/// Provides a cursor to all of the values for the duplicate entries that match this key
pub fn get<'env, R, I, C, K>(&self, reader: &'env R, k: K) -> Result<Iter<'env, I>, StoreError>
pub fn get<'r, R, I, C, K>(&self, reader: &'r R, k: K) -> Result<Iter<'r, I>, StoreError>
where
R: Readable<'env, Database = D, RoCursor = C>,
I: BackendIter<'env>,
C: BackendRoCursor<'env, Iter = I>,
R: Readable<'r, Database = D, RoCursor = C>,
I: BackendIter<'r>,
C: BackendRoCursor<'r, Iter = I>,
K: AsRef<[u8]>,
{
let cursor = reader.open_ro_cursor(&self.db)?;
@ -65,9 +65,9 @@ where
}
/// Provides the first value that matches this key
pub fn get_first<'env, R, K>(&self, reader: &'env R, k: K) -> Result<Option<Value<'env>>, StoreError>
pub fn get_first<'r, R, K>(&self, reader: &'r R, k: K) -> Result<Option<Value<'r>>, StoreError>
where
R: Readable<'env, Database = D>,
R: Readable<'r, Database = D>,
K: AsRef<[u8]>,
{
reader.get(&self.db, &k)
@ -116,11 +116,11 @@ where
}
}
impl<'env, I> Iterator for Iter<'env, I>
impl<'i, I> Iterator for Iter<'i, I>
where
I: BackendIter<'env>,
I: BackendIter<'i>,
{
type Item = Result<(&'env [u8], Option<Value<'env>>), StoreError>;
type Item = Result<(&'i [u8], Option<Value<'i>>), StoreError>;
fn next(&mut self) -> Option<Self::Item> {
match self.iter.next() {

@ -32,9 +32,9 @@ pub struct SingleStore<D> {
db: D,
}
pub struct Iter<'env, I> {
pub struct Iter<'i, I> {
iter: I,
phantom: PhantomData<&'env ()>,
phantom: PhantomData<&'i ()>,
}
impl<D> SingleStore<D>
@ -47,9 +47,9 @@ where
}
}
pub fn get<'env, R, K>(&self, reader: &'env R, k: K) -> Result<Option<Value<'env>>, StoreError>
pub fn get<'r, R, K>(&self, reader: &'r R, k: K) -> Result<Option<Value<'r>>, StoreError>
where
R: Readable<'env, Database = D>,
R: Readable<'r, Database = D>,
K: AsRef<[u8]>,
{
reader.get(&self.db, &k)
@ -82,11 +82,11 @@ where
writer.delete(&self.db, &k, None)
}
pub fn iter_start<'env, R, I, C>(&self, reader: &'env R) -> Result<Iter<'env, I>, StoreError>
pub fn iter_start<'r, R, I, C>(&self, reader: &'r R) -> Result<Iter<'r, I>, StoreError>
where
R: Readable<'env, Database = D, RoCursor = C>,
I: BackendIter<'env>,
C: BackendRoCursor<'env, Iter = I>,
R: Readable<'r, Database = D, RoCursor = C>,
I: BackendIter<'r>,
C: BackendRoCursor<'r, Iter = I>,
{
let cursor = reader.open_ro_cursor(&self.db)?;
let iter = cursor.into_iter();
@ -97,11 +97,11 @@ where
})
}
pub fn iter_from<'env, R, I, C, K>(&self, reader: &'env R, k: K) -> Result<Iter<'env, I>, StoreError>
pub fn iter_from<'r, R, I, C, K>(&self, reader: &'r R, k: K) -> Result<Iter<'r, I>, StoreError>
where
R: Readable<'env, Database = D, RoCursor = C>,
I: BackendIter<'env>,
C: BackendRoCursor<'env, Iter = I>,
R: Readable<'r, Database = D, RoCursor = C>,
I: BackendIter<'r>,
C: BackendRoCursor<'r, Iter = I>,
K: AsRef<[u8]>,
{
let cursor = reader.open_ro_cursor(&self.db)?;
@ -122,11 +122,11 @@ where
}
}
impl<'env, I> Iterator for Iter<'env, I>
impl<'i, I> Iterator for Iter<'i, I>
where
I: BackendIter<'env>,
I: BackendIter<'i>,
{
type Item = Result<(&'env [u8], Option<Value<'env>>), StoreError>;
type Item = Result<(&'i [u8], Option<Value<'i>>), StoreError>;
fn next(&mut self) -> Option<Self::Item> {
match self.iter.next() {

@ -86,16 +86,16 @@ impl fmt::Display for Type {
}
#[derive(Debug, Eq, PartialEq)]
pub enum Value<'s> {
pub enum Value<'v> {
Bool(bool),
U64(u64),
I64(i64),
F64(OrderedFloat<f64>),
Instant(i64), // Millisecond-precision timestamp.
Uuid(&'s Bytes),
Str(&'s str),
Json(&'s str),
Blob(&'s [u8]),
Uuid(&'v Bytes),
Str(&'v str),
Json(&'v str),
Blob(&'v [u8]),
}
#[derive(Clone, Debug, PartialEq)]
@ -119,14 +119,14 @@ fn uuid(bytes: &[u8]) -> Result<Value, DataError> {
}
}
impl<'s> Value<'s> {
pub fn from_tagged_slice(slice: &'s [u8]) -> Result<Value<'s>, DataError> {
impl<'v> Value<'v> {
pub fn from_tagged_slice(slice: &'v [u8]) -> Result<Value<'v>, DataError> {
let (tag, data) = slice.split_first().ok_or(DataError::Empty)?;
let t = Type::from_tag(*tag)?;
Value::from_type_and_data(t, data)
}
fn from_type_and_data(t: Type, data: &'s [u8]) -> Result<Value<'s>, DataError> {
fn from_type_and_data(t: Type, data: &'v [u8]) -> Result<Value<'v>, DataError> {
if t == Type::Uuid {
return deserialize(data)
.map_err(|e| DataError::DecodingError {
@ -187,7 +187,7 @@ impl<'s> Value<'s> {
}
}
impl<'s> From<&'s Value<'s>> for OwnedValue {
impl<'v> From<&'v Value<'v>> for OwnedValue {
fn from(value: &Value) -> OwnedValue {
match value {
Value::Bool(v) => OwnedValue::Bool(*v),
@ -203,7 +203,7 @@ impl<'s> From<&'s Value<'s>> for OwnedValue {
}
}
impl<'s> From<&'s OwnedValue> for Value<'s> {
impl<'v> From<&'v OwnedValue> for Value<'v> {
fn from(value: &OwnedValue) -> Value {
match value {
OwnedValue::Bool(v) => Value::Bool(*v),

@ -90,9 +90,9 @@ fn read_many() {
}
}
fn get_ids_by_field<'env, T>(txn: &'env T, store: MultiStore, field: &str) -> Vec<u64>
fn get_ids_by_field<'t, T>(txn: &'t T, store: MultiStore, field: &str) -> Vec<u64>
where
T: Readable<'env, Database = LmdbDatabase, RoCursor = LmdbRoCursor<'env>>,
T: Readable<'t, Database = LmdbDatabase, RoCursor = LmdbRoCursor<'t>>,
{
store
.get(txn, field)
@ -104,9 +104,9 @@ where
.collect::<Vec<u64>>()
}
fn get_samples<'env, T>(txn: &'env T, samplestore: SingleStore, ids: &[u64]) -> Vec<String>
fn get_samples<'t, T>(txn: &'t T, samplestore: SingleStore, ids: &[u64]) -> Vec<String>
where
T: Readable<'env, Database = LmdbDatabase, RoCursor = LmdbRoCursor<'env>>,
T: Readable<'t, Database = LmdbDatabase, RoCursor = LmdbRoCursor<'t>>,
{
ids.iter()
.map(|id| {

Loading…
Cancel
Save