saferlmdb 0.9.35

An almost-safe, near-zero-cost, feature-complete, unabashedly non-abstract wrapper around LMDB.
Documentation
// Copyright 2016 FullContact, Inc
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// This is not a saferlmdb module. It's included by the doc tests to provide
// common functionality.

use saferlmdb as lmdb;

#[allow(dead_code)]
fn create_env() -> lmdb::Environment {
    unsafe {
        let mut builder = lmdb::EnvBuilder::new().unwrap();
        builder.set_maxdbs(2).unwrap();
        builder
            .open(
                tempdir::TempDir::new_in(".", "lmdbzero")
                    .unwrap()
                    .path()
                    .to_str()
                    .unwrap(),
                &lmdb::open::Flags::empty(),
                0o600,
            )
            .unwrap()
    }
}

#[allow(dead_code)]
fn dupdb(env: &'_ lmdb::Environment) -> lmdb::Database<'_> {
    lmdb::Database::open(
        env,
        Some("example"),
        &lmdb::DatabaseOptions::new(lmdb::db::Flags::CREATE | lmdb::db::Flags::DUPSORT),
    )
    .unwrap()
}

#[allow(dead_code)]
fn dupfixeddb(env: &'_ lmdb::Environment) -> lmdb::Database<'_> {
    lmdb::Database::open(
        env,
        Some("example"),
        &lmdb::DatabaseOptions::new(
            lmdb::db::Flags::CREATE | lmdb::db::Flags::DUPSORT | lmdb::db::Flags::DUPFIXED,
        ),
    )
    .unwrap()
}

#[allow(dead_code)]
fn defdb(env: &'_ lmdb::Environment) -> lmdb::Database<'_> {
    lmdb::Database::open(env, None, &lmdb::DatabaseOptions::defaults()).unwrap()
}