From 881e3aae0fd3c31393e1d3597ca21290f1e2e1bf Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Wed, 6 Jul 2022 17:08:52 +0200 Subject: [PATCH 01/57] Create a sys crate that exposes the LMDB mdb.master3 branch --- .gitmodules | 3 + Cargo.toml | 2 +- README.md | 24 +- lmdb-master3-sys/.rustfmt.toml | 3 + lmdb-master3-sys/Cargo.toml | 56 ++ lmdb-master3-sys/bindgen.rs | 73 ++ lmdb-master3-sys/build.rs | 86 ++ lmdb-master3-sys/lmdb | 1 + lmdb-master3-sys/src/bindings.rs | 1531 ++++++++++++++++++++++++++++++ lmdb-master3-sys/src/lib.rs | 23 + 10 files changed, 1797 insertions(+), 5 deletions(-) create mode 100644 .gitmodules create mode 100644 lmdb-master3-sys/.rustfmt.toml create mode 100644 lmdb-master3-sys/Cargo.toml create mode 100644 lmdb-master3-sys/bindgen.rs create mode 100644 lmdb-master3-sys/build.rs create mode 160000 lmdb-master3-sys/lmdb create mode 100644 lmdb-master3-sys/src/bindings.rs create mode 100644 lmdb-master3-sys/src/lib.rs diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..2691a76f --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "lmdb-master3-sys/lmdb"] + path = lmdb-master3-sys/lmdb + url = https://github.com/LMDB/lmdb diff --git a/Cargo.toml b/Cargo.toml index b8066c4f..1ea0bfb8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,2 +1,2 @@ [workspace] -members = ["heed", "heed-traits", "heed-types"] +members = ["lmdb-master3-sys", "heed", "heed-traits", "heed-types"] diff --git a/README.md b/README.md index 16bdbcf2..9370a533 100644 --- a/README.md +++ b/README.md @@ -14,18 +14,18 @@ This library is able to serialize all kind of types, not just bytes slices, even ## Example Usage ```rust -fs::create_dir_all("target/heed.mdb")?; -let env = EnvOpenOptions::new().open("target/heed.mdb")?; +fs::create_dir_all("my-env.mdb")?; +let env = EnvOpenOptions::new().max_dbs(10).open("my-env.mdb")?; // We open the default unamed database. // Specifying the type of the newly created database. // Here we specify that the key is an str and the value a simple integer. -let db: Database> = env.create_database(None)?; +let mut wtxn = env.write_txn()?; +let db: Database> = env.create_database(&mut wtxn, None)?; // We then open a write transaction and start writing into the database. // All of those puts are type checked at compile time, // therefore you cannot write an integer instead of a string. -let mut wtxn = env.write_txn()?; db.put(&mut wtxn, "seven", &7)?; db.put(&mut wtxn, "zero", &0)?; db.put(&mut wtxn, "five", &5)?; @@ -44,3 +44,19 @@ assert_eq!(ret, Some(5)); ``` You want to see more about all the possibilities? Go check out [the examples](heed/examples/). + +## Building from Source + +If you don't already have clone the repository you can use this command: + +```bash +git clone --recursive https://github.com/meilisearch/heed.git +cd heed +cargo build +``` + +However, if you already cloned it and forgot about the initialising the submodules: + +```bash +git submodule update --init +``` diff --git a/lmdb-master3-sys/.rustfmt.toml b/lmdb-master3-sys/.rustfmt.toml new file mode 100644 index 00000000..fc441bba --- /dev/null +++ b/lmdb-master3-sys/.rustfmt.toml @@ -0,0 +1,3 @@ +ignore = [ + "src/bindings.rs" +] \ No newline at end of file diff --git a/lmdb-master3-sys/Cargo.toml b/lmdb-master3-sys/Cargo.toml new file mode 100644 index 00000000..ec0bfc61 --- /dev/null +++ b/lmdb-master3-sys/Cargo.toml @@ -0,0 +1,56 @@ +[package] +name = "lmdb-master3-sys" +# NB: When modifying, also modify html_root_url in lib.rs +version = "0.1.0" +authors = [ + "Kerollmops ", + "Dan Burkert ", + "Victor Porof ", +] +license = "Apache-2.0" +description = "Rust bindings for liblmdb on the mdb.master3 branch." +documentation = "https://docs.rs/lmdb-master3-sys" +homepage = "https://github.com/meilisearch/heed/tree/HEAD/lmdb-master3-sys" +repository = "https://github.com/meilisearch/heed.git" +keywords = ["LMDB", "database", "storage-engine", "bindings", "library"] +categories = ["database", "external-ffi-bindings"] +edition = "2021" + +# NB: Use "--features bindgen" to generate bindings. +build = "build.rs" + +[lib] +name = "lmdb_master3_sys" + +[dependencies] +libc = "0.2" + +[build-dependencies] +pkg-config = "0.3" +cc = "1.0" +bindgen = { version = "0.53.2", default-features = false, optional = true, features = ["runtime"] } + +[features] +default = [] +with-asan = [] +with-fuzzer = [] +with-fuzzer-no-link = [] + +# These features configure the MDB_IDL_LOGN macro, which determines +# the size of the free and dirty page lists (and thus the amount of memory +# allocated when opening an LMDB environment in read-write mode). +# +# Each feature defines MDB_IDL_LOGN as the value in the name of the feature. +# That means these features are mutually exclusive, and you must not specify +# more than one at the same time (or the crate will fail to compile). +# +# For more information on the motivation for these features (and their effect), +# see https://github.com/mozilla/lmdb/pull/2. +mdb_idl_logn_8 = [] +mdb_idl_logn_9 = [] +mdb_idl_logn_10 = [] +mdb_idl_logn_11 = [] +mdb_idl_logn_12 = [] +mdb_idl_logn_13 = [] +mdb_idl_logn_14 = [] +mdb_idl_logn_15 = [] diff --git a/lmdb-master3-sys/bindgen.rs b/lmdb-master3-sys/bindgen.rs new file mode 100644 index 00000000..d997757f --- /dev/null +++ b/lmdb-master3-sys/bindgen.rs @@ -0,0 +1,73 @@ +use bindgen::callbacks::IntKind; +use bindgen::callbacks::ParseCallbacks; +use std::env; +use std::path::PathBuf; + +#[derive(Debug)] +struct Callbacks; + +impl ParseCallbacks for Callbacks { + fn int_macro(&self, name: &str, _value: i64) -> Option { + match name { + "MDB_SUCCESS" + | "MDB_KEYEXIST" + | "MDB_NOTFOUND" + | "MDB_PAGE_NOTFOUND" + | "MDB_CORRUPTED" + | "MDB_PANIC" + | "MDB_VERSION_MISMATCH" + | "MDB_INVALID" + | "MDB_MAP_FULL" + | "MDB_DBS_FULL" + | "MDB_READERS_FULL" + | "MDB_TLS_FULL" + | "MDB_TXN_FULL" + | "MDB_CURSOR_FULL" + | "MDB_PAGE_FULL" + | "MDB_MAP_RESIZED" + | "MDB_INCOMPATIBLE" + | "MDB_BAD_RSLOT" + | "MDB_BAD_TXN" + | "MDB_BAD_VALSIZE" + | "MDB_BAD_DBI" + | "MDB_LAST_ERRCODE" => Some(IntKind::Int), + "MDB_SIZE_MAX" => Some(IntKind::ULong), + "MDB_PROBLEM" | "MDB_BAD_CHECKSUM" | "MDB_CRYPTO_FAIL" | "MDB_ENV_ENCRYPTION" => { + Some(IntKind::Int) + } + _ => Some(IntKind::UInt), + } + } +} + +pub fn generate() { + let mut lmdb = PathBuf::from(&env::var("CARGO_MANIFEST_DIR").unwrap()); + lmdb.push("lmdb"); + lmdb.push("libraries"); + lmdb.push("liblmdb"); + + let mut out_path = PathBuf::from(&env::var("CARGO_MANIFEST_DIR").unwrap()); + out_path.push("src"); + + let bindings = bindgen::Builder::default() + .header(lmdb.join("lmdb.h").to_string_lossy()) + .whitelist_var("^(MDB|mdb)_.*") + .whitelist_type("^(MDB|mdb)_.*") + .whitelist_function("^(MDB|mdb)_.*") + .size_t_is_usize(true) + .ctypes_prefix("::libc") + .blacklist_item("mode_t") + .blacklist_item("mdb_mode_t") + .blacklist_item("mdb_filehandle_t") + .blacklist_item("^__.*") + .parse_callbacks(Box::new(Callbacks {})) + .layout_tests(false) + .prepend_enum_name(false) + .rustfmt_bindings(true) + .generate() + .expect("Unable to generate bindings"); + + bindings + .write_to_file(out_path.join("bindings.rs")) + .expect("Couldn't write bindings!"); +} diff --git a/lmdb-master3-sys/build.rs b/lmdb-master3-sys/build.rs new file mode 100644 index 00000000..213e3cc9 --- /dev/null +++ b/lmdb-master3-sys/build.rs @@ -0,0 +1,86 @@ +extern crate cc; +extern crate pkg_config; + +#[cfg(feature = "bindgen")] +extern crate bindgen; + +#[cfg(feature = "bindgen")] +#[path = "bindgen.rs"] +mod generate; + +use std::env; +use std::path::PathBuf; + +#[cfg(feature = "mdb_idl_logn_8")] +const MDB_IDL_LOGN: u8 = 8; +#[cfg(feature = "mdb_idl_logn_9")] +const MDB_IDL_LOGN: u8 = 9; +#[cfg(feature = "mdb_idl_logn_10")] +const MDB_IDL_LOGN: u8 = 10; +#[cfg(feature = "mdb_idl_logn_11")] +const MDB_IDL_LOGN: u8 = 11; +#[cfg(feature = "mdb_idl_logn_12")] +const MDB_IDL_LOGN: u8 = 12; +#[cfg(feature = "mdb_idl_logn_13")] +const MDB_IDL_LOGN: u8 = 13; +#[cfg(feature = "mdb_idl_logn_14")] +const MDB_IDL_LOGN: u8 = 14; +#[cfg(feature = "mdb_idl_logn_15")] +const MDB_IDL_LOGN: u8 = 15; +#[cfg(not(any( + feature = "mdb_idl_logn_8", + feature = "mdb_idl_logn_9", + feature = "mdb_idl_logn_10", + feature = "mdb_idl_logn_11", + feature = "mdb_idl_logn_12", + feature = "mdb_idl_logn_13", + feature = "mdb_idl_logn_14", + feature = "mdb_idl_logn_15", +)))] +const MDB_IDL_LOGN: u8 = 16; + +macro_rules! warn { + ($message:expr) => { + println!("cargo:warning={}", $message); + }; +} + +fn main() { + #[cfg(feature = "bindgen")] + generate::generate(); + + let mut lmdb = PathBuf::from(&env::var("CARGO_MANIFEST_DIR").unwrap()); + lmdb.push("lmdb"); + lmdb.push("libraries"); + lmdb.push("liblmdb"); + + if cfg!(feature = "with-fuzzer") && cfg!(feature = "with-fuzzer-no-link") { + warn!("Features `with-fuzzer` and `with-fuzzer-no-link` are mutually exclusive."); + warn!("Building with `-fsanitize=fuzzer`."); + } + + if !pkg_config::find_library("liblmdb").is_ok() { + let mut builder = cc::Build::new(); + + builder + .define("MDB_IDL_LOGN", Some(MDB_IDL_LOGN.to_string().as_str())) + .file(lmdb.join("mdb.c")) + .file(lmdb.join("midl.c")) + // https://github.com/mozilla/lmdb/blob/b7df2cac50fb41e8bd16aab4cc5fd167be9e032a/libraries/liblmdb/Makefile#L23 + .flag_if_supported("-Wno-unused-parameter") + .flag_if_supported("-Wbad-function-cast") + .flag_if_supported("-Wuninitialized"); + + if env::var("CARGO_FEATURE_WITH_ASAN").is_ok() { + builder.flag("-fsanitize=address"); + } + + if env::var("CARGO_FEATURE_WITH_FUZZER").is_ok() { + builder.flag("-fsanitize=fuzzer"); + } else if env::var("CARGO_FEATURE_WITH_FUZZER_NO_LINK").is_ok() { + builder.flag("-fsanitize=fuzzer-no-link"); + } + + builder.compile("liblmdb.a") + } +} diff --git a/lmdb-master3-sys/lmdb b/lmdb-master3-sys/lmdb new file mode 160000 index 00000000..0179cfab --- /dev/null +++ b/lmdb-master3-sys/lmdb @@ -0,0 +1 @@ +Subproject commit 0179cfab57d83ab1bec9e5bae4a3ac9101820e6e diff --git a/lmdb-master3-sys/src/bindings.rs b/lmdb-master3-sys/src/bindings.rs new file mode 100644 index 00000000..3d6af196 --- /dev/null +++ b/lmdb-master3-sys/src/bindings.rs @@ -0,0 +1,1531 @@ +/* automatically generated by rust-bindgen */ + +pub const MDB_FMT_Z: &'static [u8; 2usize] = b"z\0"; +pub const MDB_RPAGE_CACHE: ::libc::c_uint = 1; +pub const MDB_SIZE_MAX: ::libc::c_ulong = 18446744073709551615; +pub const MDB_VERSION_MAJOR: ::libc::c_uint = 0; +pub const MDB_VERSION_MINOR: ::libc::c_uint = 9; +pub const MDB_VERSION_PATCH: ::libc::c_uint = 90; +pub const MDB_VERSION_DATE: &'static [u8; 12usize] = b"May 1, 2017\0"; +pub const MDB_FIXEDMAP: ::libc::c_uint = 1; +pub const MDB_ENCRYPT: ::libc::c_uint = 8192; +pub const MDB_NOSUBDIR: ::libc::c_uint = 16384; +pub const MDB_NOSYNC: ::libc::c_uint = 65536; +pub const MDB_RDONLY: ::libc::c_uint = 131072; +pub const MDB_NOMETASYNC: ::libc::c_uint = 262144; +pub const MDB_WRITEMAP: ::libc::c_uint = 524288; +pub const MDB_MAPASYNC: ::libc::c_uint = 1048576; +pub const MDB_NOTLS: ::libc::c_uint = 2097152; +pub const MDB_NOLOCK: ::libc::c_uint = 4194304; +pub const MDB_NORDAHEAD: ::libc::c_uint = 8388608; +pub const MDB_NOMEMINIT: ::libc::c_uint = 16777216; +pub const MDB_PREVSNAPSHOT: ::libc::c_uint = 33554432; +pub const MDB_REMAP_CHUNKS: ::libc::c_uint = 67108864; +pub const MDB_REVERSEKEY: ::libc::c_uint = 2; +pub const MDB_DUPSORT: ::libc::c_uint = 4; +pub const MDB_INTEGERKEY: ::libc::c_uint = 8; +pub const MDB_DUPFIXED: ::libc::c_uint = 16; +pub const MDB_INTEGERDUP: ::libc::c_uint = 32; +pub const MDB_REVERSEDUP: ::libc::c_uint = 64; +pub const MDB_CREATE: ::libc::c_uint = 262144; +pub const MDB_NOOVERWRITE: ::libc::c_uint = 16; +pub const MDB_NODUPDATA: ::libc::c_uint = 32; +pub const MDB_CURRENT: ::libc::c_uint = 64; +pub const MDB_RESERVE: ::libc::c_uint = 65536; +pub const MDB_APPEND: ::libc::c_uint = 131072; +pub const MDB_APPENDDUP: ::libc::c_uint = 262144; +pub const MDB_MULTIPLE: ::libc::c_uint = 524288; +pub const MDB_CP_COMPACT: ::libc::c_uint = 1; +pub const MDB_SUCCESS: ::libc::c_int = 0; +pub const MDB_KEYEXIST: ::libc::c_int = -30799; +pub const MDB_NOTFOUND: ::libc::c_int = -30798; +pub const MDB_PAGE_NOTFOUND: ::libc::c_int = -30797; +pub const MDB_CORRUPTED: ::libc::c_int = -30796; +pub const MDB_PANIC: ::libc::c_int = -30795; +pub const MDB_VERSION_MISMATCH: ::libc::c_int = -30794; +pub const MDB_INVALID: ::libc::c_int = -30793; +pub const MDB_MAP_FULL: ::libc::c_int = -30792; +pub const MDB_DBS_FULL: ::libc::c_int = -30791; +pub const MDB_READERS_FULL: ::libc::c_int = -30790; +pub const MDB_TLS_FULL: ::libc::c_int = -30789; +pub const MDB_TXN_FULL: ::libc::c_int = -30788; +pub const MDB_CURSOR_FULL: ::libc::c_int = -30787; +pub const MDB_PAGE_FULL: ::libc::c_int = -30786; +pub const MDB_MAP_RESIZED: ::libc::c_int = -30785; +pub const MDB_INCOMPATIBLE: ::libc::c_int = -30784; +pub const MDB_BAD_RSLOT: ::libc::c_int = -30783; +pub const MDB_BAD_TXN: ::libc::c_int = -30782; +pub const MDB_BAD_VALSIZE: ::libc::c_int = -30781; +pub const MDB_BAD_DBI: ::libc::c_int = -30780; +pub const MDB_PROBLEM: ::libc::c_int = -30779; +pub const MDB_BAD_CHECKSUM: ::libc::c_int = -30778; +pub const MDB_CRYPTO_FAIL: ::libc::c_int = -30777; +pub const MDB_ENV_ENCRYPTION: ::libc::c_int = -30776; +pub const MDB_LAST_ERRCODE: ::libc::c_int = -30776; +#[doc = " Unsigned type used for mapsize, entry counts and page/transaction IDs."] +#[doc = ""] +#[doc = "\tIt is normally size_t, hence the name. Defining MDB_VL32 makes it"] +#[doc = "\tuint64_t, but do not try this unless you know what you are doing."] +pub type mdb_size_t = usize; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct MDB_env { + _unused: [u8; 0], +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct MDB_txn { + _unused: [u8; 0], +} +#[doc = " @brief A handle for an individual database in the DB environment."] +pub type MDB_dbi = ::libc::c_uint; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct MDB_cursor { + _unused: [u8; 0], +} +#[doc = " @brief Generic structure used for passing keys and data in and out"] +#[doc = " of the database."] +#[doc = ""] +#[doc = " Values returned from the database are valid only until a subsequent"] +#[doc = " update operation, or the end of the transaction. Do not modify or"] +#[doc = " free them, they commonly point into the database itself."] +#[doc = ""] +#[doc = " Key sizes must be between 1 and #mdb_env_get_maxkeysize() inclusive."] +#[doc = " The same applies to data sizes in databases with the #MDB_DUPSORT flag."] +#[doc = " Other data items can in theory be from 0 to 0xffffffff bytes long."] +#[repr(C)] +pub struct MDB_val { + #[doc = "< size of the data item"] + pub mv_size: usize, + #[doc = "< address of the data item"] + pub mv_data: *mut ::libc::c_void, +} +#[doc = " @brief A callback function used to compare two keys in a database"] +pub type MDB_cmp_func = ::std::option::Option< + unsafe extern "C" fn(a: *const MDB_val, b: *const MDB_val) -> ::libc::c_int, +>; +#[doc = " @brief A callback function used to relocate a position-dependent data item"] +#[doc = " in a fixed-address database."] +#[doc = ""] +#[doc = " The \\b newptr gives the item's desired address in"] +#[doc = " the memory map, and \\b oldptr gives its previous address. The item's actual"] +#[doc = " data resides at the address in \\b item. This callback is expected to walk"] +#[doc = " through the fields of the record in \\b item and modify any"] +#[doc = " values based at the \\b oldptr address to be relative to the \\b newptr address."] +#[doc = " @param[in,out] item The item that is to be relocated."] +#[doc = " @param[in] oldptr The previous address."] +#[doc = " @param[in] newptr The new address to relocate to."] +#[doc = " @param[in] relctx An application-provided context, set by #mdb_set_relctx()."] +#[doc = " @todo This feature is currently unimplemented."] +pub type MDB_rel_func = ::std::option::Option< + unsafe extern "C" fn( + item: *mut MDB_val, + oldptr: *mut ::libc::c_void, + newptr: *mut ::libc::c_void, + relctx: *mut ::libc::c_void, + ), +>; +#[doc = " @brief A callback function used to encrypt/decrypt pages in the env."] +#[doc = ""] +#[doc = " Encrypt or decrypt the data in src and store the result in dst using the"] +#[doc = " provided key. The result must be the same number of bytes as the input."] +#[doc = " @param[in] src The input data to be transformed."] +#[doc = " @param[out] dst Storage for the result."] +#[doc = " @param[in] key An array of three values: key[0] is the encryption key,"] +#[doc = " key[1] is the initialization vector, and key[2] is the authentication"] +#[doc = " data, if any."] +#[doc = " @param[in] encdec 1 to encrypt, 0 to decrypt."] +#[doc = " @return A non-zero error value on failure and 0 on success."] +pub type MDB_enc_func = ::std::option::Option< + unsafe extern "C" fn( + src: *const MDB_val, + dst: *mut MDB_val, + key: *const MDB_val, + encdec: ::libc::c_int, + ) -> ::libc::c_int, +>; +#[doc = " @brief A callback function used to checksum pages in the env."] +#[doc = ""] +#[doc = " Compute the checksum of the data in src and store the result in dst,"] +#[doc = " An optional key may be used with keyed hash algorithms."] +#[doc = " @param[in] src The input data to be transformed."] +#[doc = " @param[out] dst Storage for the result."] +#[doc = " @param[in] key An encryption key, if encryption was configured. This"] +#[doc = " parameter will be NULL if there is no key."] +pub type MDB_sum_func = ::std::option::Option< + unsafe extern "C" fn(src: *const MDB_val, dst: *mut MDB_val, key: *const MDB_val), +>; +#[doc = "< Position at first key/data item"] +pub const MDB_FIRST: MDB_cursor_op = 0; +#[doc = "< Position at first data item of current key."] +#[doc = "Only for #MDB_DUPSORT"] +pub const MDB_FIRST_DUP: MDB_cursor_op = 1; +#[doc = "< Position at key/data pair. Only for #MDB_DUPSORT"] +pub const MDB_GET_BOTH: MDB_cursor_op = 2; +#[doc = "< position at key, nearest data. Only for #MDB_DUPSORT"] +pub const MDB_GET_BOTH_RANGE: MDB_cursor_op = 3; +#[doc = "< Return key/data at current cursor position"] +pub const MDB_GET_CURRENT: MDB_cursor_op = 4; +#[doc = "< Return up to a page of duplicate data items"] +#[doc = "from current cursor position. Move cursor to prepare"] +#[doc = "for #MDB_NEXT_MULTIPLE. Only for #MDB_DUPFIXED"] +pub const MDB_GET_MULTIPLE: MDB_cursor_op = 5; +#[doc = "< Position at last key/data item"] +pub const MDB_LAST: MDB_cursor_op = 6; +#[doc = "< Position at last data item of current key."] +#[doc = "Only for #MDB_DUPSORT"] +pub const MDB_LAST_DUP: MDB_cursor_op = 7; +#[doc = "< Position at next data item"] +pub const MDB_NEXT: MDB_cursor_op = 8; +#[doc = "< Position at next data item of current key."] +#[doc = "Only for #MDB_DUPSORT"] +pub const MDB_NEXT_DUP: MDB_cursor_op = 9; +#[doc = "< Return up to a page of duplicate data items"] +#[doc = "from next cursor position. Move cursor to prepare"] +#[doc = "for #MDB_NEXT_MULTIPLE. Only for #MDB_DUPFIXED"] +pub const MDB_NEXT_MULTIPLE: MDB_cursor_op = 10; +#[doc = "< Position at first data item of next key"] +pub const MDB_NEXT_NODUP: MDB_cursor_op = 11; +#[doc = "< Position at previous data item"] +pub const MDB_PREV: MDB_cursor_op = 12; +#[doc = "< Position at previous data item of current key."] +#[doc = "Only for #MDB_DUPSORT"] +pub const MDB_PREV_DUP: MDB_cursor_op = 13; +#[doc = "< Position at last data item of previous key"] +pub const MDB_PREV_NODUP: MDB_cursor_op = 14; +#[doc = "< Position at specified key"] +pub const MDB_SET: MDB_cursor_op = 15; +#[doc = "< Position at specified key, return key + data"] +pub const MDB_SET_KEY: MDB_cursor_op = 16; +#[doc = "< Position at first key greater than or equal to specified key."] +pub const MDB_SET_RANGE: MDB_cursor_op = 17; +#[doc = "< Position at previous page and return up to"] +#[doc = "a page of duplicate data items. Only for #MDB_DUPFIXED"] +pub const MDB_PREV_MULTIPLE: MDB_cursor_op = 18; +#[doc = " @brief Cursor Get operations."] +#[doc = ""] +#[doc = "\tThis is the set of all operations for retrieving data"] +#[doc = "\tusing a cursor."] +pub type MDB_cursor_op = u32; +#[doc = " @brief Statistics for a database in the environment"] +#[repr(C)] +pub struct MDB_stat { + #[doc = "< Size of a database page."] + #[doc = "This is currently the same for all databases."] + pub ms_psize: ::libc::c_uint, + #[doc = "< Depth (height) of the B-tree"] + pub ms_depth: ::libc::c_uint, + #[doc = "< Number of internal (non-leaf) pages"] + pub ms_branch_pages: mdb_size_t, + #[doc = "< Number of leaf pages"] + pub ms_leaf_pages: mdb_size_t, + #[doc = "< Number of overflow pages"] + pub ms_overflow_pages: mdb_size_t, + #[doc = "< Number of data items"] + pub ms_entries: mdb_size_t, +} +#[doc = " @brief Information about the environment"] +#[repr(C)] +pub struct MDB_envinfo { + #[doc = "< Address of map, if fixed"] + pub me_mapaddr: *mut ::libc::c_void, + #[doc = "< Size of the data memory map"] + pub me_mapsize: mdb_size_t, + #[doc = "< ID of the last used page"] + pub me_last_pgno: mdb_size_t, + #[doc = "< ID of the last committed transaction"] + pub me_last_txnid: mdb_size_t, + #[doc = "< max reader slots in the environment"] + pub me_maxreaders: ::libc::c_uint, + #[doc = "< max reader slots used in the environment"] + pub me_numreaders: ::libc::c_uint, +} +extern "C" { + #[doc = " @brief Return the LMDB library version information."] + #[doc = ""] + #[doc = " @param[out] major if non-NULL, the library major version number is copied here"] + #[doc = " @param[out] minor if non-NULL, the library minor version number is copied here"] + #[doc = " @param[out] patch if non-NULL, the library patch version number is copied here"] + #[doc = " @retval \"version string\" The library version as a string"] + pub fn mdb_version( + major: *mut ::libc::c_int, + minor: *mut ::libc::c_int, + patch: *mut ::libc::c_int, + ) -> *mut ::libc::c_char; +} +extern "C" { + #[doc = " @brief Return a string describing a given error code."] + #[doc = ""] + #[doc = " This function is a superset of the ANSI C X3.159-1989 (ANSI C) strerror(3)"] + #[doc = " function. If the error code is greater than or equal to 0, then the string"] + #[doc = " returned by the system function strerror(3) is returned. If the error code"] + #[doc = " is less than 0, an error string corresponding to the LMDB library error is"] + #[doc = " returned. See @ref errors for a list of LMDB-specific error codes."] + #[doc = " @param[in] err The error code"] + #[doc = " @retval \"error message\" The description of the error"] + pub fn mdb_strerror(err: ::libc::c_int) -> *mut ::libc::c_char; +} +extern "C" { + #[doc = " @brief Create an LMDB environment handle."] + #[doc = ""] + #[doc = " This function allocates memory for a #MDB_env structure. To release"] + #[doc = " the allocated memory and discard the handle, call #mdb_env_close()."] + #[doc = " Before the handle may be used, it must be opened using #mdb_env_open()."] + #[doc = " Various other options may also need to be set before opening the handle,"] + #[doc = " e.g. #mdb_env_set_mapsize(), #mdb_env_set_maxreaders(), #mdb_env_set_maxdbs(),"] + #[doc = " depending on usage requirements."] + #[doc = " @param[out] env The address where the new handle will be stored"] + #[doc = " @return A non-zero error value on failure and 0 on success."] + pub fn mdb_env_create(env: *mut *mut MDB_env) -> ::libc::c_int; +} +extern "C" { + #[doc = " @brief Open an environment handle."] + #[doc = ""] + #[doc = " If this function fails, #mdb_env_close() must be called to discard the #MDB_env handle."] + #[doc = " @param[in] env An environment handle returned by #mdb_env_create()"] + #[doc = " @param[in] path The directory in which the database files reside. This"] + #[doc = " directory must already exist and be writable."] + #[doc = " @param[in] flags Special options for this environment. This parameter"] + #[doc = " must be set to 0 or by bitwise OR'ing together one or more of the"] + #[doc = " values described here."] + #[doc = " Flags set by mdb_env_set_flags() are also used."] + #[doc = "
    "] + #[doc = "\t
  • #MDB_FIXEDMAP"] + #[doc = " use a fixed address for the mmap region. This flag must be specified"] + #[doc = " when creating the environment, and is stored persistently in the environment."] + #[doc = "\t\tIf successful, the memory map will always reside at the same virtual address"] + #[doc = "\t\tand pointers used to reference data items in the database will be constant"] + #[doc = "\t\tacross multiple invocations. This option may not always work, depending on"] + #[doc = "\t\thow the operating system has allocated memory to shared libraries and other uses."] + #[doc = "\t\tThe feature is highly experimental."] + #[doc = "\t
  • #MDB_NOSUBDIR"] + #[doc = "\t\tBy default, LMDB creates its environment in a directory whose"] + #[doc = "\t\tpathname is given in \\b path, and creates its data and lock files"] + #[doc = "\t\tunder that directory. With this option, \\b path is used as-is for"] + #[doc = "\t\tthe database main data file. The database lock file is the \\b path"] + #[doc = "\t\twith \"-lock\" appended."] + #[doc = "\t
  • #MDB_RDONLY"] + #[doc = "\t\tOpen the environment in read-only mode. No write operations will be"] + #[doc = "\t\tallowed. LMDB will still modify the lock file - except on read-only"] + #[doc = "\t\tfilesystems, where LMDB does not use locks."] + #[doc = "\t
  • #MDB_WRITEMAP"] + #[doc = "\t\tUse a writeable memory map unless MDB_RDONLY is set. This uses"] + #[doc = "\t\tfewer mallocs but loses protection from application bugs"] + #[doc = "\t\tlike wild pointer writes and other bad updates into the database."] + #[doc = "\t\tThis may be slightly faster for DBs that fit entirely in RAM, but"] + #[doc = "\t\tis slower for DBs larger than RAM."] + #[doc = "\t\tIncompatible with nested transactions."] + #[doc = "\t\tDo not mix processes with and without MDB_WRITEMAP on the same"] + #[doc = "\t\tenvironment. This can defeat durability (#mdb_env_sync etc)."] + #[doc = "\t
  • #MDB_NOMETASYNC"] + #[doc = "\t\tFlush system buffers to disk only once per transaction, omit the"] + #[doc = "\t\tmetadata flush. Defer that until the system flushes files to disk,"] + #[doc = "\t\tor next non-MDB_RDONLY commit or #mdb_env_sync(). This optimization"] + #[doc = "\t\tmaintains database integrity, but a system crash may undo the last"] + #[doc = "\t\tcommitted transaction. I.e. it preserves the ACI (atomicity,"] + #[doc = "\t\tconsistency, isolation) but not D (durability) database property."] + #[doc = "\t\tThis flag may be changed at any time using #mdb_env_set_flags()."] + #[doc = "\t
  • #MDB_NOSYNC"] + #[doc = "\t\tDon't flush system buffers to disk when committing a transaction."] + #[doc = "\t\tThis optimization means a system crash can corrupt the database or"] + #[doc = "\t\tlose the last transactions if buffers are not yet flushed to disk."] + #[doc = "\t\tThe risk is governed by how often the system flushes dirty buffers"] + #[doc = "\t\tto disk and how often #mdb_env_sync() is called. However, if the"] + #[doc = "\t\tfilesystem preserves write order and the #MDB_WRITEMAP flag is not"] + #[doc = "\t\tused, transactions exhibit ACI (atomicity, consistency, isolation)"] + #[doc = "\t\tproperties and only lose D (durability). I.e. database integrity"] + #[doc = "\t\tis maintained, but a system crash may undo the final transactions."] + #[doc = "\t\tNote that (#MDB_NOSYNC | #MDB_WRITEMAP) leaves the system with no"] + #[doc = "\t\thint for when to write transactions to disk, unless #mdb_env_sync()"] + #[doc = "\t\tis called. (#MDB_MAPASYNC | #MDB_WRITEMAP) may be preferable."] + #[doc = "\t\tThis flag may be changed at any time using #mdb_env_set_flags()."] + #[doc = "\t
  • #MDB_MAPASYNC"] + #[doc = "\t\tWhen using #MDB_WRITEMAP, use asynchronous flushes to disk."] + #[doc = "\t\tAs with #MDB_NOSYNC, a system crash can then corrupt the"] + #[doc = "\t\tdatabase or lose the last transactions. Calling #mdb_env_sync()"] + #[doc = "\t\tensures on-disk database integrity until next commit."] + #[doc = "\t\tThis flag may be changed at any time using #mdb_env_set_flags()."] + #[doc = "\t
  • #MDB_NOTLS"] + #[doc = "\t\tDon't use Thread-Local Storage. Tie reader locktable slots to"] + #[doc = "\t\t#MDB_txn objects instead of to threads. I.e. #mdb_txn_reset() keeps"] + #[doc = "\t\tthe slot reserved for the #MDB_txn object. A thread may use parallel"] + #[doc = "\t\tread-only transactions. A read-only transaction may span threads if"] + #[doc = "\t\tthe user synchronizes its use. Applications that multiplex many"] + #[doc = "\t\tuser threads over individual OS threads need this option. Such an"] + #[doc = "\t\tapplication must also serialize the write transactions in an OS"] + #[doc = "\t\tthread, since LMDB's write locking is unaware of the user threads."] + #[doc = "\t
  • #MDB_NOLOCK"] + #[doc = "\t\tDon't do any locking. If concurrent access is anticipated, the"] + #[doc = "\t\tcaller must manage all concurrency itself. For proper operation"] + #[doc = "\t\tthe caller must enforce single-writer semantics, and must ensure"] + #[doc = "\t\tthat no readers are using old transactions while a writer is"] + #[doc = "\t\tactive. The simplest approach is to use an exclusive lock so that"] + #[doc = "\t\tno readers may be active at all when a writer begins."] + #[doc = "\t
  • #MDB_NORDAHEAD"] + #[doc = "\t\tTurn off readahead. Most operating systems perform readahead on"] + #[doc = "\t\tread requests by default. This option turns it off if the OS"] + #[doc = "\t\tsupports it. Turning it off may help random read performance"] + #[doc = "\t\twhen the DB is larger than RAM and system RAM is full."] + #[doc = "\t\tThe option is not implemented on Windows."] + #[doc = "\t
  • #MDB_NOMEMINIT"] + #[doc = "\t\tDon't initialize malloc'd memory before writing to unused spaces"] + #[doc = "\t\tin the data file. By default, memory for pages written to the data"] + #[doc = "\t\tfile is obtained using malloc. While these pages may be reused in"] + #[doc = "\t\tsubsequent transactions, freshly malloc'd pages will be initialized"] + #[doc = "\t\tto zeroes before use. This avoids persisting leftover data from other"] + #[doc = "\t\tcode (that used the heap and subsequently freed the memory) into the"] + #[doc = "\t\tdata file. Note that many other system libraries may allocate"] + #[doc = "\t\tand free memory from the heap for arbitrary uses. E.g., stdio may"] + #[doc = "\t\tuse the heap for file I/O buffers. This initialization step has a"] + #[doc = "\t\tmodest performance cost so some applications may want to disable"] + #[doc = "\t\tit using this flag. This option can be a problem for applications"] + #[doc = "\t\twhich handle sensitive data like passwords, and it makes memory"] + #[doc = "\t\tcheckers like Valgrind noisy. This flag is not needed with #MDB_WRITEMAP,"] + #[doc = "\t\twhich writes directly to the mmap instead of using malloc for pages. The"] + #[doc = "\t\tinitialization is also skipped if #MDB_RESERVE is used; the"] + #[doc = "\t\tcaller is expected to overwrite all of the memory that was"] + #[doc = "\t\treserved in that case."] + #[doc = "\t\tThis flag may be changed at any time using #mdb_env_set_flags()."] + #[doc = "\t
  • #MDB_PREVSNAPSHOT"] + #[doc = "\t\tOpen the environment with the previous snapshot rather than the latest"] + #[doc = "\t\tone. This loses the latest transaction, but may help work around some"] + #[doc = "\t\ttypes of corruption. If opened with write access, this must be the"] + #[doc = "\t\tonly process using the environment. This flag is automatically reset"] + #[doc = "\t\tafter a write transaction is successfully committed."] + #[doc = "
"] + #[doc = " @param[in] mode The UNIX permissions to set on created files and semaphores."] + #[doc = " This parameter is ignored on Windows."] + #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] + #[doc = " errors are:"] + #[doc = "
    "] + #[doc = "\t
  • #MDB_VERSION_MISMATCH - the version of the LMDB library doesn't match the"] + #[doc = "\tversion that created the database environment."] + #[doc = "\t
  • #MDB_INVALID - the environment file headers are corrupted."] + #[doc = "\t
  • ENOENT - the directory specified by the path parameter doesn't exist."] + #[doc = "\t
  • EACCES - the user didn't have permission to access the environment files."] + #[doc = "\t
  • EAGAIN - the environment was locked by another process."] + #[doc = "
"] + pub fn mdb_env_open( + env: *mut MDB_env, + path: *const ::libc::c_char, + flags: ::libc::c_uint, + mode: mdb_mode_t, + ) -> ::libc::c_int; +} +extern "C" { + #[doc = " @brief Copy an LMDB environment to the specified path."] + #[doc = ""] + #[doc = " This function may be used to make a backup of an existing environment."] + #[doc = " No lockfile is created, since it gets recreated at need."] + #[doc = " @note This call can trigger significant file size growth if run in"] + #[doc = " parallel with write transactions, because it employs a read-only"] + #[doc = " transaction. See long-lived transactions under @ref caveats_sec."] + #[doc = " @param[in] env An environment handle returned by #mdb_env_create(). It"] + #[doc = " must have already been opened successfully."] + #[doc = " @param[in] path The directory in which the copy will reside. This"] + #[doc = " directory must already exist and be writable but must otherwise be"] + #[doc = " empty."] + #[doc = " @return A non-zero error value on failure and 0 on success."] + pub fn mdb_env_copy(env: *mut MDB_env, path: *const ::libc::c_char) -> ::libc::c_int; +} +extern "C" { + #[doc = " @brief Copy an LMDB environment to the specified file descriptor."] + #[doc = ""] + #[doc = " This function may be used to make a backup of an existing environment."] + #[doc = " No lockfile is created, since it gets recreated at need."] + #[doc = " @note This call can trigger significant file size growth if run in"] + #[doc = " parallel with write transactions, because it employs a read-only"] + #[doc = " transaction. See long-lived transactions under @ref caveats_sec."] + #[doc = " @param[in] env An environment handle returned by #mdb_env_create(). It"] + #[doc = " must have already been opened successfully."] + #[doc = " @param[in] fd The filedescriptor to write the copy to. It must"] + #[doc = " have already been opened for Write access."] + #[doc = " @return A non-zero error value on failure and 0 on success."] + pub fn mdb_env_copyfd(env: *mut MDB_env, fd: mdb_filehandle_t) -> ::libc::c_int; +} +extern "C" { + #[doc = " @brief Copy an LMDB environment to the specified path, with options."] + #[doc = ""] + #[doc = " This function may be used to make a backup of an existing environment."] + #[doc = " No lockfile is created, since it gets recreated at need."] + #[doc = " @note This call can trigger significant file size growth if run in"] + #[doc = " parallel with write transactions, because it employs a read-only"] + #[doc = " transaction. See long-lived transactions under @ref caveats_sec."] + #[doc = " @param[in] env An environment handle returned by #mdb_env_create(). It"] + #[doc = " must have already been opened successfully."] + #[doc = " @param[in] path The directory in which the copy will reside. This"] + #[doc = " directory must already exist and be writable but must otherwise be"] + #[doc = " empty."] + #[doc = " @param[in] flags Special options for this operation. This parameter"] + #[doc = " must be set to 0 or by bitwise OR'ing together one or more of the"] + #[doc = " values described here."] + #[doc = "
    "] + #[doc = "\t
  • #MDB_CP_COMPACT - Perform compaction while copying: omit free"] + #[doc = "\t\tpages and sequentially renumber all pages in output. This option"] + #[doc = "\t\tconsumes more CPU and runs more slowly than the default."] + #[doc = "\t\tCurrently it fails if the environment has suffered a page leak."] + #[doc = "
"] + #[doc = " @return A non-zero error value on failure and 0 on success."] + pub fn mdb_env_copy2( + env: *mut MDB_env, + path: *const ::libc::c_char, + flags: ::libc::c_uint, + ) -> ::libc::c_int; +} +extern "C" { + #[doc = " @brief Copy an LMDB environment to the specified file descriptor,"] + #[doc = "\twith options."] + #[doc = ""] + #[doc = " This function may be used to make a backup of an existing environment."] + #[doc = " No lockfile is created, since it gets recreated at need. See"] + #[doc = " #mdb_env_copy2() for further details."] + #[doc = " @note This call can trigger significant file size growth if run in"] + #[doc = " parallel with write transactions, because it employs a read-only"] + #[doc = " transaction. See long-lived transactions under @ref caveats_sec."] + #[doc = " @param[in] env An environment handle returned by #mdb_env_create(). It"] + #[doc = " must have already been opened successfully."] + #[doc = " @param[in] fd The filedescriptor to write the copy to. It must"] + #[doc = " have already been opened for Write access."] + #[doc = " @param[in] flags Special options for this operation."] + #[doc = " See #mdb_env_copy2() for options."] + #[doc = " @return A non-zero error value on failure and 0 on success."] + pub fn mdb_env_copyfd2( + env: *mut MDB_env, + fd: mdb_filehandle_t, + flags: ::libc::c_uint, + ) -> ::libc::c_int; +} +extern "C" { + #[doc = " @brief Return statistics about the LMDB environment."] + #[doc = ""] + #[doc = " @param[in] env An environment handle returned by #mdb_env_create()"] + #[doc = " @param[out] stat The address of an #MDB_stat structure"] + #[doc = " \twhere the statistics will be copied"] + pub fn mdb_env_stat(env: *mut MDB_env, stat: *mut MDB_stat) -> ::libc::c_int; +} +extern "C" { + #[doc = " @brief Return information about the LMDB environment."] + #[doc = ""] + #[doc = " @param[in] env An environment handle returned by #mdb_env_create()"] + #[doc = " @param[out] stat The address of an #MDB_envinfo structure"] + #[doc = " \twhere the information will be copied"] + pub fn mdb_env_info(env: *mut MDB_env, stat: *mut MDB_envinfo) -> ::libc::c_int; +} +extern "C" { + #[doc = " @brief Flush the data buffers to disk."] + #[doc = ""] + #[doc = " Data is always written to disk when #mdb_txn_commit() is called,"] + #[doc = " but the operating system may keep it buffered. LMDB always flushes"] + #[doc = " the OS buffers upon commit as well, unless the environment was"] + #[doc = " opened with #MDB_NOSYNC or in part #MDB_NOMETASYNC. This call is"] + #[doc = " not valid if the environment was opened with #MDB_RDONLY."] + #[doc = " @param[in] env An environment handle returned by #mdb_env_create()"] + #[doc = " @param[in] force If non-zero, force a synchronous flush. Otherwise"] + #[doc = " if the environment has the #MDB_NOSYNC flag set the flushes"] + #[doc = "\twill be omitted, and with #MDB_MAPASYNC they will be asynchronous."] + #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] + #[doc = " errors are:"] + #[doc = "
    "] + #[doc = "\t
  • EACCES - the environment is read-only."] + #[doc = "\t
  • EINVAL - an invalid parameter was specified."] + #[doc = "\t
  • EIO - an error occurred during synchronization."] + #[doc = "
"] + pub fn mdb_env_sync(env: *mut MDB_env, force: ::libc::c_int) -> ::libc::c_int; +} +extern "C" { + #[doc = " @brief Close the environment and release the memory map."] + #[doc = ""] + #[doc = " Only a single thread may call this function. All transactions, databases,"] + #[doc = " and cursors must already be closed before calling this function. Attempts to"] + #[doc = " use any such handles after calling this function will cause a SIGSEGV."] + #[doc = " The environment handle will be freed and must not be used again after this call."] + #[doc = " @param[in] env An environment handle returned by #mdb_env_create()"] + pub fn mdb_env_close(env: *mut MDB_env); +} +extern "C" { + #[doc = " @brief Set environment flags."] + #[doc = ""] + #[doc = " This may be used to set some flags in addition to those from"] + #[doc = " #mdb_env_open(), or to unset these flags. If several threads"] + #[doc = " change the flags at the same time, the result is undefined."] + #[doc = " @param[in] env An environment handle returned by #mdb_env_create()"] + #[doc = " @param[in] flags The flags to change, bitwise OR'ed together"] + #[doc = " @param[in] onoff A non-zero value sets the flags, zero clears them."] + #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] + #[doc = " errors are:"] + #[doc = "
    "] + #[doc = "\t
  • EINVAL - an invalid parameter was specified."] + #[doc = "
"] + pub fn mdb_env_set_flags( + env: *mut MDB_env, + flags: ::libc::c_uint, + onoff: ::libc::c_int, + ) -> ::libc::c_int; +} +extern "C" { + #[doc = " @brief Get environment flags."] + #[doc = ""] + #[doc = " @param[in] env An environment handle returned by #mdb_env_create()"] + #[doc = " @param[out] flags The address of an integer to store the flags"] + #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] + #[doc = " errors are:"] + #[doc = "
    "] + #[doc = "\t
  • EINVAL - an invalid parameter was specified."] + #[doc = "
"] + pub fn mdb_env_get_flags(env: *mut MDB_env, flags: *mut ::libc::c_uint) -> ::libc::c_int; +} +extern "C" { + #[doc = " @brief Return the path that was used in #mdb_env_open()."] + #[doc = ""] + #[doc = " @param[in] env An environment handle returned by #mdb_env_create()"] + #[doc = " @param[out] path Address of a string pointer to contain the path. This"] + #[doc = " is the actual string in the environment, not a copy. It should not be"] + #[doc = " altered in any way."] + #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] + #[doc = " errors are:"] + #[doc = "
    "] + #[doc = "\t
  • EINVAL - an invalid parameter was specified."] + #[doc = "
"] + pub fn mdb_env_get_path(env: *mut MDB_env, path: *mut *const ::libc::c_char) -> ::libc::c_int; +} +extern "C" { + #[doc = " @brief Return the filedescriptor for the given environment."] + #[doc = ""] + #[doc = " This function may be called after fork(), so the descriptor can be"] + #[doc = " closed before exec*(). Other LMDB file descriptors have FD_CLOEXEC."] + #[doc = " (Until LMDB 0.9.18, only the lockfile had that.)"] + #[doc = ""] + #[doc = " @param[in] env An environment handle returned by #mdb_env_create()"] + #[doc = " @param[out] fd Address of a mdb_filehandle_t to contain the descriptor."] + #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] + #[doc = " errors are:"] + #[doc = "
    "] + #[doc = "\t
  • EINVAL - an invalid parameter was specified."] + #[doc = "
"] + pub fn mdb_env_get_fd(env: *mut MDB_env, fd: *mut mdb_filehandle_t) -> ::libc::c_int; +} +extern "C" { + #[doc = " @brief Set the size of the memory map to use for this environment."] + #[doc = ""] + #[doc = " The size should be a multiple of the OS page size. The default is"] + #[doc = " 10485760 bytes. The size of the memory map is also the maximum size"] + #[doc = " of the database. The value should be chosen as large as possible,"] + #[doc = " to accommodate future growth of the database."] + #[doc = " This function should be called after #mdb_env_create() and before #mdb_env_open()."] + #[doc = " It may be called at later times if no transactions are active in"] + #[doc = " this process. Note that the library does not check for this condition,"] + #[doc = " the caller must ensure it explicitly."] + #[doc = ""] + #[doc = " The new size takes effect immediately for the current process but"] + #[doc = " will not be persisted to any others until a write transaction has been"] + #[doc = " committed by the current process. Also, only mapsize increases are"] + #[doc = " persisted into the environment."] + #[doc = ""] + #[doc = " If the mapsize is increased by another process, and data has grown"] + #[doc = " beyond the range of the current mapsize, #mdb_txn_begin() will"] + #[doc = " return #MDB_MAP_RESIZED. This function may be called with a size"] + #[doc = " of zero to adopt the new size."] + #[doc = ""] + #[doc = " Any attempt to set a size smaller than the space already consumed"] + #[doc = " by the environment will be silently changed to the current size of the used space."] + #[doc = " @param[in] env An environment handle returned by #mdb_env_create()"] + #[doc = " @param[in] size The size in bytes"] + #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] + #[doc = " errors are:"] + #[doc = "
    "] + #[doc = "\t
  • EINVAL - an invalid parameter was specified, or the environment has"] + #[doc = " \tan active write transaction."] + #[doc = "
"] + pub fn mdb_env_set_mapsize(env: *mut MDB_env, size: mdb_size_t) -> ::libc::c_int; +} +extern "C" { + #[doc = " @brief Set the size of DB pages in bytes."] + #[doc = ""] + #[doc = " The size defaults to the OS page size. Smaller or larger values may be"] + #[doc = " desired depending on the size of keys and values being used. Also, an"] + #[doc = " explicit size may need to be set when using filesystems like ZFS which"] + #[doc = " don't use the OS page size."] + pub fn mdb_env_set_pagesize(env: *mut MDB_env, size: ::libc::c_int) -> ::libc::c_int; +} +extern "C" { + #[doc = " @brief Set the maximum number of threads/reader slots for the environment."] + #[doc = ""] + #[doc = " This defines the number of slots in the lock table that is used to track readers in the"] + #[doc = " the environment. The default is 126."] + #[doc = " Starting a read-only transaction normally ties a lock table slot to the"] + #[doc = " current thread until the environment closes or the thread exits. If"] + #[doc = " MDB_NOTLS is in use, #mdb_txn_begin() instead ties the slot to the"] + #[doc = " MDB_txn object until it or the #MDB_env object is destroyed."] + #[doc = " This function may only be called after #mdb_env_create() and before #mdb_env_open()."] + #[doc = " @param[in] env An environment handle returned by #mdb_env_create()"] + #[doc = " @param[in] readers The maximum number of reader lock table slots"] + #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] + #[doc = " errors are:"] + #[doc = "
    "] + #[doc = "\t
  • EINVAL - an invalid parameter was specified, or the environment is already open."] + #[doc = "
"] + pub fn mdb_env_set_maxreaders(env: *mut MDB_env, readers: ::libc::c_uint) -> ::libc::c_int; +} +extern "C" { + #[doc = " @brief Get the maximum number of threads/reader slots for the environment."] + #[doc = ""] + #[doc = " @param[in] env An environment handle returned by #mdb_env_create()"] + #[doc = " @param[out] readers Address of an integer to store the number of readers"] + #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] + #[doc = " errors are:"] + #[doc = "
    "] + #[doc = "\t
  • EINVAL - an invalid parameter was specified."] + #[doc = "
"] + pub fn mdb_env_get_maxreaders(env: *mut MDB_env, readers: *mut ::libc::c_uint) + -> ::libc::c_int; +} +extern "C" { + #[doc = " @brief Set the maximum number of named databases for the environment."] + #[doc = ""] + #[doc = " This function is only needed if multiple databases will be used in the"] + #[doc = " environment. Simpler applications that use the environment as a single"] + #[doc = " unnamed database can ignore this option."] + #[doc = " This function may only be called after #mdb_env_create() and before #mdb_env_open()."] + #[doc = ""] + #[doc = " Currently a moderate number of slots are cheap but a huge number gets"] + #[doc = " expensive: 7-120 words per transaction, and every #mdb_dbi_open()"] + #[doc = " does a linear search of the opened slots."] + #[doc = " @param[in] env An environment handle returned by #mdb_env_create()"] + #[doc = " @param[in] dbs The maximum number of databases"] + #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] + #[doc = " errors are:"] + #[doc = "
    "] + #[doc = "\t
  • EINVAL - an invalid parameter was specified, or the environment is already open."] + #[doc = "
"] + pub fn mdb_env_set_maxdbs(env: *mut MDB_env, dbs: MDB_dbi) -> ::libc::c_int; +} +extern "C" { + #[doc = " @brief Get the maximum size of keys and #MDB_DUPSORT data we can write."] + #[doc = ""] + #[doc = " Depends on the compile-time constant #MDB_MAXKEYSIZE. Default 511."] + #[doc = " See @ref MDB_val."] + #[doc = " @param[in] env An environment handle returned by #mdb_env_create()"] + #[doc = " @return The maximum size of a key we can write"] + pub fn mdb_env_get_maxkeysize(env: *mut MDB_env) -> ::libc::c_int; +} +extern "C" { + #[doc = " @brief Set application information associated with the #MDB_env."] + #[doc = ""] + #[doc = " @param[in] env An environment handle returned by #mdb_env_create()"] + #[doc = " @param[in] ctx An arbitrary pointer for whatever the application needs."] + #[doc = " @return A non-zero error value on failure and 0 on success."] + pub fn mdb_env_set_userctx(env: *mut MDB_env, ctx: *mut ::libc::c_void) -> ::libc::c_int; +} +extern "C" { + #[doc = " @brief Get the application information associated with the #MDB_env."] + #[doc = ""] + #[doc = " @param[in] env An environment handle returned by #mdb_env_create()"] + #[doc = " @return The pointer set by #mdb_env_set_userctx()."] + pub fn mdb_env_get_userctx(env: *mut MDB_env) -> *mut ::libc::c_void; +} +#[doc = " @brief A callback function for most LMDB assert() failures,"] +#[doc = " called before printing the message and aborting."] +#[doc = ""] +#[doc = " @param[in] env An environment handle returned by #mdb_env_create()."] +#[doc = " @param[in] msg The assertion message, not including newline."] +pub type MDB_assert_func = + ::std::option::Option; +extern "C" { + #[doc = " Set or reset the assert() callback of the environment."] + #[doc = " Disabled if liblmdb is built with NDEBUG."] + #[doc = " @note This hack should become obsolete as lmdb's error handling matures."] + #[doc = " @param[in] env An environment handle returned by #mdb_env_create()."] + #[doc = " @param[in] func An #MDB_assert_func function, or 0."] + #[doc = " @return A non-zero error value on failure and 0 on success."] + pub fn mdb_env_set_assert(env: *mut MDB_env, func: MDB_assert_func) -> ::libc::c_int; +} +extern "C" { + #[doc = " @brief Set encryption on an environment."] + #[doc = ""] + #[doc = " This must be called before #mdb_env_open()."] + #[doc = " It implicitly sets #MDB_REMAP_CHUNKS on the env."] + #[doc = " @param[in] env An environment handle returned by #mdb_env_create()."] + #[doc = " @param[in] func An #MDB_enc_func function."] + #[doc = " @param[in] key The encryption key."] + #[doc = " @param[in] size The size of authentication data in bytes, if any."] + #[doc = " Set this to zero for unauthenticated encryption mechanisms."] + #[doc = " @return A non-zero error value on failure and 0 on success."] + pub fn mdb_env_set_encrypt( + env: *mut MDB_env, + func: MDB_enc_func, + key: *const MDB_val, + size: ::libc::c_uint, + ) -> ::libc::c_int; +} +extern "C" { + #[doc = " @brief Set checksums on an environment."] + #[doc = ""] + #[doc = " This must be called before #mdb_env_open()."] + #[doc = " @param[in] env An environment handle returned by #mdb_env_create()."] + #[doc = " @param[in] func An #MDB_sum_func function."] + #[doc = " @param[in] size The size of computed checksum values, in bytes."] + #[doc = " @return A non-zero error value on failure and 0 on success."] + pub fn mdb_env_set_checksum( + env: *mut MDB_env, + func: MDB_sum_func, + size: ::libc::c_uint, + ) -> ::libc::c_int; +} +extern "C" { + #[doc = " @brief Create a transaction for use with the environment."] + #[doc = ""] + #[doc = " The transaction handle may be discarded using #mdb_txn_abort() or #mdb_txn_commit()."] + #[doc = " @note A transaction and its cursors must only be used by a single"] + #[doc = " thread, and a thread may only have a single transaction at a time."] + #[doc = " If #MDB_NOTLS is in use, this does not apply to read-only transactions."] + #[doc = " @note Cursors may not span transactions."] + #[doc = " @param[in] env An environment handle returned by #mdb_env_create()"] + #[doc = " @param[in] parent If this parameter is non-NULL, the new transaction"] + #[doc = " will be a nested transaction, with the transaction indicated by \\b parent"] + #[doc = " as its parent. Transactions may be nested to any level. A parent"] + #[doc = " transaction and its cursors may not issue any other operations than"] + #[doc = " mdb_txn_commit and mdb_txn_abort while it has active child transactions."] + #[doc = " @param[in] flags Special options for this transaction. This parameter"] + #[doc = " must be set to 0 or by bitwise OR'ing together one or more of the"] + #[doc = " values described here."] + #[doc = "
    "] + #[doc = "\t
  • #MDB_RDONLY"] + #[doc = "\t\tThis transaction will not perform any write operations."] + #[doc = "\t
  • #MDB_NOSYNC"] + #[doc = "\t\tDon't flush system buffers to disk when committing this transaction."] + #[doc = "\t
  • #MDB_NOMETASYNC"] + #[doc = "\t\tFlush system buffers but omit metadata flush when committing this transaction."] + #[doc = "
"] + #[doc = " @param[out] txn Address where the new #MDB_txn handle will be stored"] + #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] + #[doc = " errors are:"] + #[doc = "
    "] + #[doc = "\t
  • #MDB_PANIC - a fatal error occurred earlier and the environment"] + #[doc = "\t\tmust be shut down."] + #[doc = "\t
  • #MDB_MAP_RESIZED - another process wrote data beyond this MDB_env's"] + #[doc = "\t\tmapsize and this environment's map must be resized as well."] + #[doc = "\t\tSee #mdb_env_set_mapsize()."] + #[doc = "\t
  • #MDB_READERS_FULL - a read-only transaction was requested and"] + #[doc = "\t\tthe reader lock table is full. See #mdb_env_set_maxreaders()."] + #[doc = "\t
  • ENOMEM - out of memory."] + #[doc = "
"] + pub fn mdb_txn_begin( + env: *mut MDB_env, + parent: *mut MDB_txn, + flags: ::libc::c_uint, + txn: *mut *mut MDB_txn, + ) -> ::libc::c_int; +} +extern "C" { + #[doc = " @brief Returns the transaction's #MDB_env"] + #[doc = ""] + #[doc = " @param[in] txn A transaction handle returned by #mdb_txn_begin()"] + pub fn mdb_txn_env(txn: *mut MDB_txn) -> *mut MDB_env; +} +extern "C" { + #[doc = " @brief Return the transaction's ID."] + #[doc = ""] + #[doc = " This returns the identifier associated with this transaction. For a"] + #[doc = " read-only transaction, this corresponds to the snapshot being read;"] + #[doc = " concurrent readers will frequently have the same transaction ID."] + #[doc = ""] + #[doc = " @param[in] txn A transaction handle returned by #mdb_txn_begin()"] + #[doc = " @return A transaction ID, valid if input is an active transaction."] + pub fn mdb_txn_id(txn: *mut MDB_txn) -> mdb_size_t; +} +extern "C" { + #[doc = " @brief Commit all the operations of a transaction into the database."] + #[doc = ""] + #[doc = " The transaction handle is freed. It and its cursors must not be used"] + #[doc = " again after this call, except with #mdb_cursor_renew()."] + #[doc = " @note Earlier documentation incorrectly said all cursors would be freed."] + #[doc = " Only write-transactions free cursors."] + #[doc = " @param[in] txn A transaction handle returned by #mdb_txn_begin()"] + #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] + #[doc = " errors are:"] + #[doc = "
    "] + #[doc = "\t
  • EINVAL - an invalid parameter was specified."] + #[doc = "\t
  • ENOSPC - no more disk space."] + #[doc = "\t
  • EIO - a low-level I/O error occurred while writing."] + #[doc = "\t
  • ENOMEM - out of memory."] + #[doc = "
"] + pub fn mdb_txn_commit(txn: *mut MDB_txn) -> ::libc::c_int; +} +extern "C" { + #[doc = " @brief Abandon all the operations of the transaction instead of saving them."] + #[doc = ""] + #[doc = " The transaction handle is freed. It and its cursors must not be used"] + #[doc = " again after this call, except with #mdb_cursor_renew()."] + #[doc = " @note Earlier documentation incorrectly said all cursors would be freed."] + #[doc = " Only write-transactions free cursors."] + #[doc = " @param[in] txn A transaction handle returned by #mdb_txn_begin()"] + pub fn mdb_txn_abort(txn: *mut MDB_txn); +} +extern "C" { + #[doc = " @brief Reset a read-only transaction."] + #[doc = ""] + #[doc = " Abort the transaction like #mdb_txn_abort(), but keep the transaction"] + #[doc = " handle. #mdb_txn_renew() may reuse the handle. This saves allocation"] + #[doc = " overhead if the process will start a new read-only transaction soon,"] + #[doc = " and also locking overhead if #MDB_NOTLS is in use. The reader table"] + #[doc = " lock is released, but the table slot stays tied to its thread or"] + #[doc = " #MDB_txn. Use mdb_txn_abort() to discard a reset handle, and to free"] + #[doc = " its lock table slot if MDB_NOTLS is in use."] + #[doc = " Cursors opened within the transaction must not be used"] + #[doc = " again after this call, except with #mdb_cursor_renew()."] + #[doc = " Reader locks generally don't interfere with writers, but they keep old"] + #[doc = " versions of database pages allocated. Thus they prevent the old pages"] + #[doc = " from being reused when writers commit new data, and so under heavy load"] + #[doc = " the database size may grow much more rapidly than otherwise."] + #[doc = " @param[in] txn A transaction handle returned by #mdb_txn_begin()"] + pub fn mdb_txn_reset(txn: *mut MDB_txn); +} +extern "C" { + #[doc = " @brief Renew a read-only transaction."] + #[doc = ""] + #[doc = " This acquires a new reader lock for a transaction handle that had been"] + #[doc = " released by #mdb_txn_reset(). It must be called before a reset transaction"] + #[doc = " may be used again."] + #[doc = " @param[in] txn A transaction handle returned by #mdb_txn_begin()"] + #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] + #[doc = " errors are:"] + #[doc = "
    "] + #[doc = "\t
  • #MDB_PANIC - a fatal error occurred earlier and the environment"] + #[doc = "\t\tmust be shut down."] + #[doc = "\t
  • EINVAL - an invalid parameter was specified."] + #[doc = "
"] + pub fn mdb_txn_renew(txn: *mut MDB_txn) -> ::libc::c_int; +} +extern "C" { + #[doc = " @brief Open a database in the environment."] + #[doc = ""] + #[doc = " A database handle denotes the name and parameters of a database,"] + #[doc = " independently of whether such a database exists."] + #[doc = " The database handle may be discarded by calling #mdb_dbi_close()."] + #[doc = " The old database handle is returned if the database was already open."] + #[doc = " The handle may only be closed once."] + #[doc = ""] + #[doc = " The database handle will be private to the current transaction until"] + #[doc = " the transaction is successfully committed. If the transaction is"] + #[doc = " aborted the handle will be closed automatically."] + #[doc = " After a successful commit the handle will reside in the shared"] + #[doc = " environment, and may be used by other transactions."] + #[doc = ""] + #[doc = " This function must not be called from multiple concurrent"] + #[doc = " transactions in the same process. A transaction that uses"] + #[doc = " this function must finish (either commit or abort) before"] + #[doc = " any other transaction in the process may use this function."] + #[doc = ""] + #[doc = " To use named databases (with name != NULL), #mdb_env_set_maxdbs()"] + #[doc = " must be called before opening the environment. Database names are"] + #[doc = " keys in the unnamed database, and may be read but not written."] + #[doc = " @note Names are C strings and stored with their NUL terminator included."] + #[doc = " In LMDB 0.9 the NUL terminator was omitted."] + #[doc = ""] + #[doc = " @param[in] txn A transaction handle returned by #mdb_txn_begin()"] + #[doc = " @param[in] name The name of the database to open. If only a single"] + #[doc = " \tdatabase is needed in the environment, this value may be NULL."] + #[doc = " @param[in] flags Special options for this database. This parameter"] + #[doc = " must be set to 0 or by bitwise OR'ing together one or more of the"] + #[doc = " values described here."] + #[doc = "
    "] + #[doc = "\t
  • #MDB_REVERSEKEY"] + #[doc = "\t\tKeys are strings to be compared in reverse order, from the end"] + #[doc = "\t\tof the strings to the beginning. By default, Keys are treated as strings and"] + #[doc = "\t\tcompared from beginning to end."] + #[doc = "\t
  • #MDB_DUPSORT"] + #[doc = "\t\tDuplicate keys may be used in the database. (Or, from another perspective,"] + #[doc = "\t\tkeys may have multiple data items, stored in sorted order.) By default"] + #[doc = "\t\tkeys must be unique and may have only a single data item."] + #[doc = "\t
  • #MDB_INTEGERKEY"] + #[doc = "\t\tKeys are binary integers in native byte order, either unsigned int"] + #[doc = "\t\tor #mdb_size_t, and will be sorted as such."] + #[doc = "\t\t(lmdb expects 32-bit int <= size_t <= 32/64-bit mdb_size_t.)"] + #[doc = "\t\tThe keys must all be of the same size."] + #[doc = "\t
  • #MDB_DUPFIXED"] + #[doc = "\t\tThis flag may only be used in combination with #MDB_DUPSORT. This option"] + #[doc = "\t\ttells the library that the data items for this database are all the same"] + #[doc = "\t\tsize, which allows further optimizations in storage and retrieval. When"] + #[doc = "\t\tall data items are the same size, the #MDB_GET_MULTIPLE, #MDB_NEXT_MULTIPLE"] + #[doc = "\t\tand #MDB_PREV_MULTIPLE cursor operations may be used to retrieve multiple"] + #[doc = "\t\titems at once."] + #[doc = "\t
  • #MDB_INTEGERDUP"] + #[doc = "\t\tThis option specifies that duplicate data items are binary integers,"] + #[doc = "\t\tsimilar to #MDB_INTEGERKEY keys."] + #[doc = "\t
  • #MDB_REVERSEDUP"] + #[doc = "\t\tThis option specifies that duplicate data items should be compared as"] + #[doc = "\t\tstrings in reverse order."] + #[doc = "\t
  • #MDB_CREATE"] + #[doc = "\t\tCreate the named database if it doesn't exist. This option is not"] + #[doc = "\t\tallowed in a read-only transaction or a read-only environment."] + #[doc = "
"] + #[doc = " @param[out] dbi Address where the new #MDB_dbi handle will be stored"] + #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] + #[doc = " errors are:"] + #[doc = "
    "] + #[doc = "\t
  • #MDB_NOTFOUND - the specified database doesn't exist in the environment"] + #[doc = "\t\tand #MDB_CREATE was not specified."] + #[doc = "\t
  • #MDB_DBS_FULL - too many databases have been opened. See #mdb_env_set_maxdbs()."] + #[doc = "
"] + pub fn mdb_dbi_open( + txn: *mut MDB_txn, + name: *const ::libc::c_char, + flags: ::libc::c_uint, + dbi: *mut MDB_dbi, + ) -> ::libc::c_int; +} +extern "C" { + #[doc = " @brief Retrieve statistics for a database."] + #[doc = ""] + #[doc = " @param[in] txn A transaction handle returned by #mdb_txn_begin()"] + #[doc = " @param[in] dbi A database handle returned by #mdb_dbi_open()"] + #[doc = " @param[out] stat The address of an #MDB_stat structure"] + #[doc = " \twhere the statistics will be copied"] + #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] + #[doc = " errors are:"] + #[doc = "
    "] + #[doc = "\t
  • EINVAL - an invalid parameter was specified."] + #[doc = "
"] + pub fn mdb_stat(txn: *mut MDB_txn, dbi: MDB_dbi, stat: *mut MDB_stat) -> ::libc::c_int; +} +extern "C" { + #[doc = " @brief Retrieve the DB flags for a database handle."] + #[doc = ""] + #[doc = " @param[in] txn A transaction handle returned by #mdb_txn_begin()"] + #[doc = " @param[in] dbi A database handle returned by #mdb_dbi_open()"] + #[doc = " @param[out] flags Address where the flags will be returned."] + #[doc = " @return A non-zero error value on failure and 0 on success."] + pub fn mdb_dbi_flags( + txn: *mut MDB_txn, + dbi: MDB_dbi, + flags: *mut ::libc::c_uint, + ) -> ::libc::c_int; +} +extern "C" { + #[doc = " @brief Close a database handle. Normally unnecessary. Use with care:"] + #[doc = ""] + #[doc = " This call is not mutex protected. Handles should only be closed by"] + #[doc = " a single thread, and only if no other threads are going to reference"] + #[doc = " the database handle or one of its cursors any further. Do not close"] + #[doc = " a handle if an existing transaction has modified its database."] + #[doc = " Doing so can cause misbehavior from database corruption to errors"] + #[doc = " like MDB_BAD_VALSIZE (since the DB name is gone)."] + #[doc = ""] + #[doc = " Closing a database handle is not necessary, but lets #mdb_dbi_open()"] + #[doc = " reuse the handle value. Usually it's better to set a bigger"] + #[doc = " #mdb_env_set_maxdbs(), unless that value would be large."] + #[doc = ""] + #[doc = " @param[in] env An environment handle returned by #mdb_env_create()"] + #[doc = " @param[in] dbi A database handle returned by #mdb_dbi_open()"] + pub fn mdb_dbi_close(env: *mut MDB_env, dbi: MDB_dbi); +} +extern "C" { + #[doc = " @brief Empty or delete+close a database."] + #[doc = ""] + #[doc = " See #mdb_dbi_close() for restrictions about closing the DB handle."] + #[doc = " @param[in] txn A transaction handle returned by #mdb_txn_begin()"] + #[doc = " @param[in] dbi A database handle returned by #mdb_dbi_open()"] + #[doc = " @param[in] del 0 to empty the DB, 1 to delete it from the"] + #[doc = " environment and close the DB handle."] + #[doc = " @return A non-zero error value on failure and 0 on success."] + pub fn mdb_drop(txn: *mut MDB_txn, dbi: MDB_dbi, del: ::libc::c_int) -> ::libc::c_int; +} +extern "C" { + #[doc = " @brief Set a custom key comparison function for a database."] + #[doc = ""] + #[doc = " The comparison function is called whenever it is necessary to compare a"] + #[doc = " key specified by the application with a key currently stored in the database."] + #[doc = " If no comparison function is specified, and no special key flags were specified"] + #[doc = " with #mdb_dbi_open(), the keys are compared lexically, with shorter keys collating"] + #[doc = " before longer keys."] + #[doc = " @warning This function must be called before any data access functions are used,"] + #[doc = " otherwise data corruption may occur. The same comparison function must be used by every"] + #[doc = " program accessing the database, every time the database is used."] + #[doc = " @param[in] txn A transaction handle returned by #mdb_txn_begin()"] + #[doc = " @param[in] dbi A database handle returned by #mdb_dbi_open()"] + #[doc = " @param[in] cmp A #MDB_cmp_func function"] + #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] + #[doc = " errors are:"] + #[doc = "
    "] + #[doc = "\t
  • EINVAL - an invalid parameter was specified."] + #[doc = "
"] + pub fn mdb_set_compare(txn: *mut MDB_txn, dbi: MDB_dbi, cmp: MDB_cmp_func) -> ::libc::c_int; +} +extern "C" { + #[doc = " @brief Set a custom data comparison function for a #MDB_DUPSORT database."] + #[doc = ""] + #[doc = " This comparison function is called whenever it is necessary to compare a data"] + #[doc = " item specified by the application with a data item currently stored in the database."] + #[doc = " This function only takes effect if the database was opened with the #MDB_DUPSORT"] + #[doc = " flag."] + #[doc = " If no comparison function is specified, and no special key flags were specified"] + #[doc = " with #mdb_dbi_open(), the data items are compared lexically, with shorter items collating"] + #[doc = " before longer items."] + #[doc = " @warning This function must be called before any data access functions are used,"] + #[doc = " otherwise data corruption may occur. The same comparison function must be used by every"] + #[doc = " program accessing the database, every time the database is used."] + #[doc = " @param[in] txn A transaction handle returned by #mdb_txn_begin()"] + #[doc = " @param[in] dbi A database handle returned by #mdb_dbi_open()"] + #[doc = " @param[in] cmp A #MDB_cmp_func function"] + #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] + #[doc = " errors are:"] + #[doc = "
    "] + #[doc = "\t
  • EINVAL - an invalid parameter was specified."] + #[doc = "
"] + pub fn mdb_set_dupsort(txn: *mut MDB_txn, dbi: MDB_dbi, cmp: MDB_cmp_func) -> ::libc::c_int; +} +extern "C" { + #[doc = " @brief Set a relocation function for a #MDB_FIXEDMAP database."] + #[doc = ""] + #[doc = " @todo The relocation function is called whenever it is necessary to move the data"] + #[doc = " of an item to a different position in the database (e.g. through tree"] + #[doc = " balancing operations, shifts as a result of adds or deletes, etc.). It is"] + #[doc = " intended to allow address/position-dependent data items to be stored in"] + #[doc = " a database in an environment opened with the #MDB_FIXEDMAP option."] + #[doc = " Currently the relocation feature is unimplemented and setting"] + #[doc = " this function has no effect."] + #[doc = " @param[in] txn A transaction handle returned by #mdb_txn_begin()"] + #[doc = " @param[in] dbi A database handle returned by #mdb_dbi_open()"] + #[doc = " @param[in] rel A #MDB_rel_func function"] + #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] + #[doc = " errors are:"] + #[doc = "
    "] + #[doc = "\t
  • EINVAL - an invalid parameter was specified."] + #[doc = "
"] + pub fn mdb_set_relfunc(txn: *mut MDB_txn, dbi: MDB_dbi, rel: MDB_rel_func) -> ::libc::c_int; +} +extern "C" { + #[doc = " @brief Set a context pointer for a #MDB_FIXEDMAP database's relocation function."] + #[doc = ""] + #[doc = " See #mdb_set_relfunc and #MDB_rel_func for more details."] + #[doc = " @param[in] txn A transaction handle returned by #mdb_txn_begin()"] + #[doc = " @param[in] dbi A database handle returned by #mdb_dbi_open()"] + #[doc = " @param[in] ctx An arbitrary pointer for whatever the application needs."] + #[doc = " It will be passed to the callback function set by #mdb_set_relfunc"] + #[doc = " as its \\b relctx parameter whenever the callback is invoked."] + #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] + #[doc = " errors are:"] + #[doc = "
    "] + #[doc = "\t
  • EINVAL - an invalid parameter was specified."] + #[doc = "
"] + pub fn mdb_set_relctx( + txn: *mut MDB_txn, + dbi: MDB_dbi, + ctx: *mut ::libc::c_void, + ) -> ::libc::c_int; +} +extern "C" { + #[doc = " @brief Get items from a database."] + #[doc = ""] + #[doc = " This function retrieves key/data pairs from the database. The address"] + #[doc = " and length of the data associated with the specified \\b key are returned"] + #[doc = " in the structure to which \\b data refers."] + #[doc = " If the database supports duplicate keys (#MDB_DUPSORT) then the"] + #[doc = " first data item for the key will be returned. Retrieval of other"] + #[doc = " items requires the use of #mdb_cursor_get()."] + #[doc = ""] + #[doc = " @note The memory pointed to by the returned values is owned by the"] + #[doc = " database. The caller need not dispose of the memory, and may not"] + #[doc = " modify it in any way. For values returned in a read-only transaction"] + #[doc = " any modification attempts will cause a SIGSEGV."] + #[doc = " @note Values returned from the database are valid only until a"] + #[doc = " subsequent update operation, or the end of the transaction."] + #[doc = " @param[in] txn A transaction handle returned by #mdb_txn_begin()"] + #[doc = " @param[in] dbi A database handle returned by #mdb_dbi_open()"] + #[doc = " @param[in] key The key to search for in the database"] + #[doc = " @param[out] data The data corresponding to the key"] + #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] + #[doc = " errors are:"] + #[doc = "
    "] + #[doc = "\t
  • #MDB_NOTFOUND - the key was not in the database."] + #[doc = "\t
  • EINVAL - an invalid parameter was specified."] + #[doc = "
"] + pub fn mdb_get( + txn: *mut MDB_txn, + dbi: MDB_dbi, + key: *mut MDB_val, + data: *mut MDB_val, + ) -> ::libc::c_int; +} +extern "C" { + #[doc = " @brief Store items into a database."] + #[doc = ""] + #[doc = " This function stores key/data pairs in the database. The default behavior"] + #[doc = " is to enter the new key/data pair, replacing any previously existing key"] + #[doc = " if duplicates are disallowed, or adding a duplicate data item if"] + #[doc = " duplicates are allowed (#MDB_DUPSORT)."] + #[doc = " @param[in] txn A transaction handle returned by #mdb_txn_begin()"] + #[doc = " @param[in] dbi A database handle returned by #mdb_dbi_open()"] + #[doc = " @param[in] key The key to store in the database"] + #[doc = " @param[in,out] data The data to store"] + #[doc = " @param[in] flags Special options for this operation. This parameter"] + #[doc = " must be set to 0 or by bitwise OR'ing together one or more of the"] + #[doc = " values described here."] + #[doc = "
    "] + #[doc = "\t
  • #MDB_NODUPDATA - enter the new key/data pair only if it does not"] + #[doc = "\t\talready appear in the database. This flag may only be specified"] + #[doc = "\t\tif the database was opened with #MDB_DUPSORT. The function will"] + #[doc = "\t\treturn #MDB_KEYEXIST if the key/data pair already appears in the"] + #[doc = "\t\tdatabase."] + #[doc = "\t
  • #MDB_NOOVERWRITE - enter the new key/data pair only if the key"] + #[doc = "\t\tdoes not already appear in the database. The function will return"] + #[doc = "\t\t#MDB_KEYEXIST if the key already appears in the database, even if"] + #[doc = "\t\tthe database supports duplicates (#MDB_DUPSORT). The \\b data"] + #[doc = "\t\tparameter will be set to point to the existing item."] + #[doc = "\t
  • #MDB_RESERVE - reserve space for data of the given size, but"] + #[doc = "\t\tdon't copy the given data. Instead, return a pointer to the"] + #[doc = "\t\treserved space, which the caller can fill in later - before"] + #[doc = "\t\tthe next update operation or the transaction ends. This saves"] + #[doc = "\t\tan extra memcpy if the data is being generated later."] + #[doc = "\t\tLMDB does nothing else with this memory, the caller is expected"] + #[doc = "\t\tto modify all of the space requested. This flag must not be"] + #[doc = "\t\tspecified if the database was opened with #MDB_DUPSORT."] + #[doc = "\t
  • #MDB_APPEND - append the given key/data pair to the end of the"] + #[doc = "\t\tdatabase. This option allows fast bulk loading when keys are"] + #[doc = "\t\talready known to be in the correct order. Loading unsorted keys"] + #[doc = "\t\twith this flag will cause a #MDB_KEYEXIST error."] + #[doc = "\t
  • #MDB_APPENDDUP - as above, but for sorted dup data."] + #[doc = "
"] + #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] + #[doc = " errors are:"] + #[doc = "
    "] + #[doc = "\t
  • #MDB_MAP_FULL - the database is full, see #mdb_env_set_mapsize()."] + #[doc = "\t
  • #MDB_TXN_FULL - the transaction has too many dirty pages."] + #[doc = "\t
  • EACCES - an attempt was made to write in a read-only transaction."] + #[doc = "\t
  • EINVAL - an invalid parameter was specified."] + #[doc = "
"] + pub fn mdb_put( + txn: *mut MDB_txn, + dbi: MDB_dbi, + key: *mut MDB_val, + data: *mut MDB_val, + flags: ::libc::c_uint, + ) -> ::libc::c_int; +} +extern "C" { + #[doc = " @brief Delete items from a database."] + #[doc = ""] + #[doc = " This function removes key/data pairs from the database."] + #[doc = " If the database does not support sorted duplicate data items"] + #[doc = " (#MDB_DUPSORT) the data parameter is ignored."] + #[doc = " If the database supports sorted duplicates and the data parameter"] + #[doc = " is NULL, all of the duplicate data items for the key will be"] + #[doc = " deleted. Otherwise, if the data parameter is non-NULL"] + #[doc = " only the matching data item will be deleted."] + #[doc = " This function will return #MDB_NOTFOUND if the specified key/data"] + #[doc = " pair is not in the database."] + #[doc = " @param[in] txn A transaction handle returned by #mdb_txn_begin()"] + #[doc = " @param[in] dbi A database handle returned by #mdb_dbi_open()"] + #[doc = " @param[in] key The key to delete from the database"] + #[doc = " @param[in] data The data to delete"] + #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] + #[doc = " errors are:"] + #[doc = "
    "] + #[doc = "\t
  • EACCES - an attempt was made to write in a read-only transaction."] + #[doc = "\t
  • EINVAL - an invalid parameter was specified."] + #[doc = "
"] + pub fn mdb_del( + txn: *mut MDB_txn, + dbi: MDB_dbi, + key: *mut MDB_val, + data: *mut MDB_val, + ) -> ::libc::c_int; +} +extern "C" { + #[doc = " @brief Create a cursor handle."] + #[doc = ""] + #[doc = " A cursor is associated with a specific transaction and database."] + #[doc = " A cursor cannot be used when its database handle is closed. Nor"] + #[doc = " when its transaction has ended, except with #mdb_cursor_renew()."] + #[doc = " It can be discarded with #mdb_cursor_close()."] + #[doc = " A cursor in a write-transaction can be closed before its transaction"] + #[doc = " ends, and will otherwise be closed when its transaction ends."] + #[doc = " A cursor in a read-only transaction must be closed explicitly, before"] + #[doc = " or after its transaction ends. It can be reused with"] + #[doc = " #mdb_cursor_renew() before finally closing it."] + #[doc = " @note Earlier documentation said that cursors in every transaction"] + #[doc = " were closed when the transaction committed or aborted."] + #[doc = " @param[in] txn A transaction handle returned by #mdb_txn_begin()"] + #[doc = " @param[in] dbi A database handle returned by #mdb_dbi_open()"] + #[doc = " @param[out] cursor Address where the new #MDB_cursor handle will be stored"] + #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] + #[doc = " errors are:"] + #[doc = "
    "] + #[doc = "\t
  • EINVAL - an invalid parameter was specified."] + #[doc = "
"] + pub fn mdb_cursor_open( + txn: *mut MDB_txn, + dbi: MDB_dbi, + cursor: *mut *mut MDB_cursor, + ) -> ::libc::c_int; +} +extern "C" { + #[doc = " @brief Close a cursor handle."] + #[doc = ""] + #[doc = " The cursor handle will be freed and must not be used again after this call."] + #[doc = " Its transaction must still be live if it is a write-transaction."] + #[doc = " @param[in] cursor A cursor handle returned by #mdb_cursor_open()"] + pub fn mdb_cursor_close(cursor: *mut MDB_cursor); +} +extern "C" { + #[doc = " @brief Renew a cursor handle."] + #[doc = ""] + #[doc = " A cursor is associated with a specific transaction and database."] + #[doc = " Cursors that are only used in read-only"] + #[doc = " transactions may be re-used, to avoid unnecessary malloc/free overhead."] + #[doc = " The cursor may be associated with a new read-only transaction, and"] + #[doc = " referencing the same database handle as it was created with."] + #[doc = " This may be done whether the previous transaction is live or dead."] + #[doc = " @param[in] txn A transaction handle returned by #mdb_txn_begin()"] + #[doc = " @param[in] cursor A cursor handle returned by #mdb_cursor_open()"] + #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] + #[doc = " errors are:"] + #[doc = "
    "] + #[doc = "\t
  • EINVAL - an invalid parameter was specified."] + #[doc = "
"] + pub fn mdb_cursor_renew(txn: *mut MDB_txn, cursor: *mut MDB_cursor) -> ::libc::c_int; +} +extern "C" { + #[doc = " @brief Return the cursor's transaction handle."] + #[doc = ""] + #[doc = " @param[in] cursor A cursor handle returned by #mdb_cursor_open()"] + pub fn mdb_cursor_txn(cursor: *mut MDB_cursor) -> *mut MDB_txn; +} +extern "C" { + #[doc = " @brief Return the cursor's database handle."] + #[doc = ""] + #[doc = " @param[in] cursor A cursor handle returned by #mdb_cursor_open()"] + pub fn mdb_cursor_dbi(cursor: *mut MDB_cursor) -> MDB_dbi; +} +extern "C" { + #[doc = " @brief Check if the cursor is pointing to a named database record."] + #[doc = ""] + #[doc = " @param[in] cursor A cursor handle returned by #mdb_cursor_open()"] + #[doc = " @return 1 if current record is a named database, 0 otherwise."] + pub fn mdb_cursor_is_db(cursor: *mut MDB_cursor) -> ::libc::c_int; +} +extern "C" { + #[doc = " @brief Retrieve by cursor."] + #[doc = ""] + #[doc = " This function retrieves key/data pairs from the database. The address and length"] + #[doc = " of the key are returned in the object to which \\b key refers (except for the"] + #[doc = " case of the #MDB_SET option, in which the \\b key object is unchanged), and"] + #[doc = " the address and length of the data are returned in the object to which \\b data"] + #[doc = " refers."] + #[doc = " See #mdb_get() for restrictions on using the output values."] + #[doc = " @param[in] cursor A cursor handle returned by #mdb_cursor_open()"] + #[doc = " @param[in,out] key The key for a retrieved item"] + #[doc = " @param[in,out] data The data of a retrieved item"] + #[doc = " @param[in] op A cursor operation #MDB_cursor_op"] + #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] + #[doc = " errors are:"] + #[doc = "
    "] + #[doc = "\t
  • #MDB_NOTFOUND - no matching key found."] + #[doc = "\t
  • EINVAL - an invalid parameter was specified."] + #[doc = "
"] + pub fn mdb_cursor_get( + cursor: *mut MDB_cursor, + key: *mut MDB_val, + data: *mut MDB_val, + op: MDB_cursor_op, + ) -> ::libc::c_int; +} +extern "C" { + #[doc = " @brief Store by cursor."] + #[doc = ""] + #[doc = " This function stores key/data pairs into the database."] + #[doc = " The cursor is positioned at the new item, or on failure usually near it."] + #[doc = " @note Earlier documentation incorrectly said errors would leave the"] + #[doc = " state of the cursor unchanged."] + #[doc = " @param[in] cursor A cursor handle returned by #mdb_cursor_open()"] + #[doc = " @param[in] key The key operated on."] + #[doc = " @param[in] data The data operated on."] + #[doc = " @param[in] flags Options for this operation. This parameter"] + #[doc = " must be set to 0 or one of the values described here."] + #[doc = "
    "] + #[doc = "\t
  • #MDB_CURRENT - replace the item at the current cursor position."] + #[doc = "\t\tThe \\b key parameter must still be provided, and must match it."] + #[doc = "\t\tIf using sorted duplicates (#MDB_DUPSORT) the data item must still"] + #[doc = "\t\tsort into the same place. This is intended to be used when the"] + #[doc = "\t\tnew data is the same size as the old. Otherwise it will simply"] + #[doc = "\t\tperform a delete of the old record followed by an insert."] + #[doc = "\t
  • #MDB_NODUPDATA - enter the new key/data pair only if it does not"] + #[doc = "\t\talready appear in the database. This flag may only be specified"] + #[doc = "\t\tif the database was opened with #MDB_DUPSORT. The function will"] + #[doc = "\t\treturn #MDB_KEYEXIST if the key/data pair already appears in the"] + #[doc = "\t\tdatabase."] + #[doc = "\t
  • #MDB_NOOVERWRITE - enter the new key/data pair only if the key"] + #[doc = "\t\tdoes not already appear in the database. The function will return"] + #[doc = "\t\t#MDB_KEYEXIST if the key already appears in the database, even if"] + #[doc = "\t\tthe database supports duplicates (#MDB_DUPSORT)."] + #[doc = "\t
  • #MDB_RESERVE - reserve space for data of the given size, but"] + #[doc = "\t\tdon't copy the given data. Instead, return a pointer to the"] + #[doc = "\t\treserved space, which the caller can fill in later - before"] + #[doc = "\t\tthe next update operation or the transaction ends. This saves"] + #[doc = "\t\tan extra memcpy if the data is being generated later. This flag"] + #[doc = "\t\tmust not be specified if the database was opened with #MDB_DUPSORT."] + #[doc = "\t
  • #MDB_APPEND - append the given key/data pair to the end of the"] + #[doc = "\t\tdatabase. No key comparisons are performed. This option allows"] + #[doc = "\t\tfast bulk loading when keys are already known to be in the"] + #[doc = "\t\tcorrect order. Loading unsorted keys with this flag will cause"] + #[doc = "\t\ta #MDB_KEYEXIST error."] + #[doc = "\t
  • #MDB_APPENDDUP - as above, but for sorted dup data."] + #[doc = "\t
  • #MDB_MULTIPLE - store multiple contiguous data elements in a"] + #[doc = "\t\tsingle request. This flag may only be specified if the database"] + #[doc = "\t\twas opened with #MDB_DUPFIXED. The \\b data argument must be an"] + #[doc = "\t\tarray of two MDB_vals. The mv_size of the first MDB_val must be"] + #[doc = "\t\tthe size of a single data element. The mv_data of the first MDB_val"] + #[doc = "\t\tmust point to the beginning of the array of contiguous data elements."] + #[doc = "\t\tThe mv_size of the second MDB_val must be the count of the number"] + #[doc = "\t\tof data elements to store. On return this field will be set to"] + #[doc = "\t\tthe count of the number of elements actually written. The mv_data"] + #[doc = "\t\tof the second MDB_val is unused."] + #[doc = "
"] + #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] + #[doc = " errors are:"] + #[doc = "
    "] + #[doc = "\t
  • #MDB_MAP_FULL - the database is full, see #mdb_env_set_mapsize()."] + #[doc = "\t
  • #MDB_TXN_FULL - the transaction has too many dirty pages."] + #[doc = "\t
  • EACCES - an attempt was made to write in a read-only transaction."] + #[doc = "\t
  • EINVAL - an invalid parameter was specified."] + #[doc = "
"] + pub fn mdb_cursor_put( + cursor: *mut MDB_cursor, + key: *mut MDB_val, + data: *mut MDB_val, + flags: ::libc::c_uint, + ) -> ::libc::c_int; +} +extern "C" { + #[doc = " @brief Delete current key/data pair"] + #[doc = ""] + #[doc = " This function deletes the key/data pair to which the cursor refers."] + #[doc = " This does not invalidate the cursor, so operations such as MDB_NEXT"] + #[doc = " can still be used on it."] + #[doc = " Both MDB_NEXT and MDB_GET_CURRENT will return the same record after"] + #[doc = " this operation."] + #[doc = " @param[in] cursor A cursor handle returned by #mdb_cursor_open()"] + #[doc = " @param[in] flags Options for this operation. This parameter"] + #[doc = " must be set to 0 or one of the values described here."] + #[doc = "
    "] + #[doc = "\t
  • #MDB_NODUPDATA - delete all of the data items for the current key."] + #[doc = "\t\tThis flag may only be specified if the database was opened with #MDB_DUPSORT."] + #[doc = "
"] + #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] + #[doc = " errors are:"] + #[doc = "
    "] + #[doc = "\t
  • EACCES - an attempt was made to write in a read-only transaction."] + #[doc = "\t
  • EINVAL - an invalid parameter was specified."] + #[doc = "
"] + pub fn mdb_cursor_del(cursor: *mut MDB_cursor, flags: ::libc::c_uint) -> ::libc::c_int; +} +extern "C" { + #[doc = " @brief Return count of duplicates for current key."] + #[doc = ""] + #[doc = " This call is only valid on databases that support sorted duplicate"] + #[doc = " data items #MDB_DUPSORT."] + #[doc = " @param[in] cursor A cursor handle returned by #mdb_cursor_open()"] + #[doc = " @param[out] countp Address where the count will be stored"] + #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] + #[doc = " errors are:"] + #[doc = "
    "] + #[doc = "\t
  • EINVAL - cursor is not initialized, or an invalid parameter was specified."] + #[doc = "
"] + pub fn mdb_cursor_count(cursor: *mut MDB_cursor, countp: *mut mdb_size_t) -> ::libc::c_int; +} +extern "C" { + #[doc = " @brief Compare two data items according to a particular database."] + #[doc = ""] + #[doc = " This returns a comparison as if the two data items were keys in the"] + #[doc = " specified database."] + #[doc = " @param[in] txn A transaction handle returned by #mdb_txn_begin()"] + #[doc = " @param[in] dbi A database handle returned by #mdb_dbi_open()"] + #[doc = " @param[in] a The first item to compare"] + #[doc = " @param[in] b The second item to compare"] + #[doc = " @return < 0 if a < b, 0 if a == b, > 0 if a > b"] + pub fn mdb_cmp( + txn: *mut MDB_txn, + dbi: MDB_dbi, + a: *const MDB_val, + b: *const MDB_val, + ) -> ::libc::c_int; +} +extern "C" { + #[doc = " @brief Compare two data items according to a particular database."] + #[doc = ""] + #[doc = " This returns a comparison as if the two items were data items of"] + #[doc = " the specified database. The database must have the #MDB_DUPSORT flag."] + #[doc = " @param[in] txn A transaction handle returned by #mdb_txn_begin()"] + #[doc = " @param[in] dbi A database handle returned by #mdb_dbi_open()"] + #[doc = " @param[in] a The first item to compare"] + #[doc = " @param[in] b The second item to compare"] + #[doc = " @return < 0 if a < b, 0 if a == b, > 0 if a > b"] + pub fn mdb_dcmp( + txn: *mut MDB_txn, + dbi: MDB_dbi, + a: *const MDB_val, + b: *const MDB_val, + ) -> ::libc::c_int; +} +#[doc = " @brief A callback function used to print a message from the library."] +#[doc = ""] +#[doc = " @param[in] msg The string to be printed."] +#[doc = " @param[in] ctx An arbitrary context pointer for the callback."] +#[doc = " @return < 0 on failure, >= 0 on success."] +pub type MDB_msg_func = ::std::option::Option< + unsafe extern "C" fn(msg: *const ::libc::c_char, ctx: *mut ::libc::c_void) -> ::libc::c_int, +>; +extern "C" { + #[doc = " @brief Dump the entries in the reader lock table."] + #[doc = ""] + #[doc = " @param[in] env An environment handle returned by #mdb_env_create()"] + #[doc = " @param[in] func A #MDB_msg_func function"] + #[doc = " @param[in] ctx Anything the message function needs"] + #[doc = " @return < 0 on failure, >= 0 on success."] + pub fn mdb_reader_list( + env: *mut MDB_env, + func: MDB_msg_func, + ctx: *mut ::libc::c_void, + ) -> ::libc::c_int; +} +extern "C" { + #[doc = " @brief Check for stale entries in the reader lock table."] + #[doc = ""] + #[doc = " @param[in] env An environment handle returned by #mdb_env_create()"] + #[doc = " @param[out] dead Number of stale slots that were cleared"] + #[doc = " @return 0 on success, non-zero on failure."] + pub fn mdb_reader_check(env: *mut MDB_env, dead: *mut ::libc::c_int) -> ::libc::c_int; +} +#[doc = " @brief A function for converting a string into an encryption key."] +#[doc = ""] +#[doc = " @param[in] passwd The string to be converted."] +#[doc = " @param[in,out] key The resulting key. The caller must"] +#[doc = " provide the space for the key."] +#[doc = " @return 0 on success, non-zero on failure."] +pub type MDB_str2key_func = ::std::option::Option< + unsafe extern "C" fn(passwd: *const ::libc::c_char, key: *mut MDB_val) -> ::libc::c_int, +>; +#[doc = " @brief A structure for dynamically loaded crypto modules."] +#[doc = ""] +#[doc = " This is the information that the command line tools expect"] +#[doc = " in order to operate on encrypted or checksummed environments."] +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct MDB_crypto_funcs { + pub mcf_str2key: MDB_str2key_func, + pub mcf_encfunc: MDB_enc_func, + pub mcf_sumfunc: MDB_sum_func, + #[doc = "< The size of an encryption key, in bytes"] + pub mcf_keysize: ::libc::c_int, + #[doc = "< The size of the MAC, for authenticated encryption"] + pub mcf_esumsize: ::libc::c_int, + #[doc = "< The size of the checksum, for plain checksums"] + pub mcf_sumsize: ::libc::c_int, +} +#[doc = " @brief The function that returns the #MDB_crypto_funcs structure."] +#[doc = ""] +#[doc = " The command line tools expect this function to be named \"MDB_crypto\"."] +#[doc = " It must be exported by the dynamic module so that the tools can use it."] +#[doc = " @return A pointer to a #MDB_crypto_funcs structure."] +pub type MDB_crypto_hooks = ::std::option::Option *mut MDB_crypto_funcs>; diff --git a/lmdb-master3-sys/src/lib.rs b/lmdb-master3-sys/src/lib.rs new file mode 100644 index 00000000..9110ce16 --- /dev/null +++ b/lmdb-master3-sys/src/lib.rs @@ -0,0 +1,23 @@ +#![deny(warnings)] +#![allow(rustdoc::broken_intra_doc_links)] +#![allow(non_camel_case_types)] +#![allow(clippy::all)] +#![doc(html_root_url = "https://docs.rs/lmdb-master3-sys/0.1.0")] + +extern crate libc; + +#[cfg(unix)] +#[allow(non_camel_case_types)] +pub type mdb_mode_t = ::libc::mode_t; +#[cfg(windows)] +#[allow(non_camel_case_types)] +pub type mdb_mode_t = ::libc::c_int; + +#[cfg(unix)] +#[allow(non_camel_case_types)] +pub type mdb_filehandle_t = ::libc::c_int; +#[cfg(windows)] +#[allow(non_camel_case_types)] +pub type mdb_filehandle_t = *mut ::libc::c_void; + +include!("bindings.rs"); From b387b7ac6bba005c12e2562af0286ba8563cc8dd Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Wed, 6 Jul 2022 14:57:39 +0200 Subject: [PATCH 02/57] Use the local lmdb-master3-sys crate in heed --- heed/Cargo.toml | 2 +- heed/src/db/polymorph.rs | 116 +++++++++++++++++------------------ heed/src/db/uniform.rs | 120 ++++++++++++++++++------------------- heed/src/env.rs | 47 +++++++++------ heed/src/iter/mod.rs | 42 ++++--------- heed/src/lib.rs | 4 +- heed/src/mdb/lmdb_error.rs | 18 +++++- heed/src/mdb/lmdb_ffi.rs | 2 +- heed/src/mdb/lmdb_flags.rs | 28 ++++----- 9 files changed, 194 insertions(+), 185 deletions(-) diff --git a/heed/Cargo.toml b/heed/Cargo.toml index 19aabae2..75239b16 100644 --- a/heed/Cargo.toml +++ b/heed/Cargo.toml @@ -15,7 +15,7 @@ byteorder = { version = "1.3.4", default-features = false } heed-traits = { version = "0.7.0", path = "../heed-traits" } heed-types = { version = "0.7.2", path = "../heed-types" } libc = "0.2.80" -lmdb-rkv-sys = { git = "https://github.com/meilisearch/lmdb-rs" } +lmdb-master3-sys = { path = "../lmdb-master3-sys" } once_cell = "1.5.2" page_size = "0.4.2" serde = { version = "1.0.118", features = ["derive"], optional = true } diff --git a/heed/src/db/polymorph.rs b/heed/src/db/polymorph.rs index 684855a0..da434c88 100644 --- a/heed/src/db/polymorph.rs +++ b/heed/src/db/polymorph.rs @@ -24,11 +24,11 @@ use crate::*; /// use heed::{zerocopy::I64, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { -/// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; +/// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) -/// # .open(Path::new("target").join("zerocopy.mdb"))?; +/// # .open(dir.path())?; /// type BEI64 = I64; /// /// let db: PolyDatabase = env.create_poly_database(Some("big-endian-iter"))?; @@ -67,11 +67,11 @@ use crate::*; /// use heed::{zerocopy::I64, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { -/// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; +/// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) -/// # .open(Path::new("target").join("zerocopy.mdb"))?; +/// # .open(dir.path())?; /// type BEI64 = I64; /// /// let db: PolyDatabase = env.create_poly_database(Some("big-endian-iter"))?; @@ -125,11 +125,11 @@ impl PolyDatabase { /// use heed::types::*; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// let db = env.create_poly_database(Some("get-poly-i32"))?; /// /// let mut wtxn = env.write_txn()?; @@ -193,11 +193,11 @@ impl PolyDatabase { /// use heed::{zerocopy::U32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEU32 = U32; /// /// let db = env.create_poly_database(Some("get-lt-u32"))?; @@ -261,11 +261,11 @@ impl PolyDatabase { /// use heed::{zerocopy::U32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEU32 = U32; /// /// let db = env.create_poly_database(Some("get-lte-u32"))?; @@ -333,11 +333,11 @@ impl PolyDatabase { /// use heed::{zerocopy::U32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEU32 = U32; /// /// let db = env.create_poly_database(Some("get-lt-u32"))?; @@ -404,11 +404,11 @@ impl PolyDatabase { /// use heed::{zerocopy::U32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEU32 = U32; /// /// let db = env.create_poly_database(Some("get-lt-u32"))?; @@ -469,11 +469,11 @@ impl PolyDatabase { /// use heed::{zerocopy::I32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEI32 = I32; /// /// let db = env.create_poly_database(Some("first-poly-i32"))?; @@ -525,11 +525,11 @@ impl PolyDatabase { /// use heed::{zerocopy::I32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEI32 = I32; /// /// let db = env.create_poly_database(Some("last-i32"))?; @@ -577,11 +577,11 @@ impl PolyDatabase { /// use heed::{zerocopy::I32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEI32 = I32; /// /// let db = env.create_poly_database(Some("iter-i32"))?; @@ -633,11 +633,11 @@ impl PolyDatabase { /// use heed::{zerocopy::I32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEI32 = I32; /// /// let db = env.create_poly_database(Some("iter-i32"))?; @@ -681,11 +681,11 @@ impl PolyDatabase { /// use heed::{zerocopy::I32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEI32 = I32; /// /// let db = env.create_poly_database(Some("iter-i32"))?; @@ -723,11 +723,11 @@ impl PolyDatabase { /// use heed::{zerocopy::I32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEI32 = I32; /// /// let db = env.create_poly_database(Some("iter-i32"))?; @@ -781,11 +781,11 @@ impl PolyDatabase { /// use heed::{zerocopy::I32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEI32 = I32; /// /// let db = env.create_poly_database(Some("iter-i32"))?; @@ -827,11 +827,11 @@ impl PolyDatabase { /// use heed::{zerocopy::I32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEI32 = I32; /// /// let db = env.create_poly_database(Some("iter-i32"))?; @@ -887,11 +887,11 @@ impl PolyDatabase { /// use heed::{zerocopy::I32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEI32 = I32; /// /// let db = env.create_poly_database(Some("iter-i32"))?; @@ -965,11 +965,11 @@ impl PolyDatabase { /// use heed::{zerocopy::I32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEI32 = I32; /// /// let db = env.create_poly_database(Some("iter-i32"))?; @@ -1056,11 +1056,11 @@ impl PolyDatabase { /// use heed::{zerocopy::I32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEI32 = I32; /// /// let db = env.create_poly_database(Some("iter-i32"))?; @@ -1134,11 +1134,11 @@ impl PolyDatabase { /// use heed::{zerocopy::I32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEI32 = I32; /// /// let db = env.create_poly_database(Some("iter-i32"))?; @@ -1225,11 +1225,11 @@ impl PolyDatabase { /// use heed::{zerocopy::I32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEI32 = I32; /// /// let db = env.create_poly_database(Some("iter-i32"))?; @@ -1281,11 +1281,11 @@ impl PolyDatabase { /// use heed::{zerocopy::I32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEI32 = I32; /// /// let db = env.create_poly_database(Some("iter-i32"))?; @@ -1350,11 +1350,11 @@ impl PolyDatabase { /// use heed::{zerocopy::I32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEI32 = I32; /// /// let db = env.create_poly_database(Some("iter-i32"))?; @@ -1406,11 +1406,11 @@ impl PolyDatabase { /// use heed::{zerocopy::I32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEI32 = I32; /// /// let db = env.create_poly_database(Some("iter-i32"))?; @@ -1472,11 +1472,11 @@ impl PolyDatabase { /// use heed::{zerocopy::I32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEI32 = I32; /// /// let db = env.create_poly_database(Some("iter-i32"))?; @@ -1534,11 +1534,11 @@ impl PolyDatabase { /// use heed::{zerocopy::I32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEI32 = I32; /// /// let db = env.create_poly_database(Some("append-i32"))?; @@ -1595,11 +1595,11 @@ impl PolyDatabase { /// use heed::{zerocopy::I32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEI32 = I32; /// /// let db = env.create_poly_database(Some("iter-i32"))?; @@ -1661,11 +1661,11 @@ impl PolyDatabase { /// use heed::{zerocopy::I32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEI32 = I32; /// /// let db = env.create_poly_database(Some("iter-i32"))?; @@ -1731,11 +1731,11 @@ impl PolyDatabase { /// use heed::{zerocopy::I32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEI32 = I32; /// /// let db = env.create_poly_database(Some("iter-i32"))?; @@ -1780,11 +1780,11 @@ impl PolyDatabase { /// use heed::{zerocopy::I32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEI32 = I32; /// /// let db = env.create_poly_database(Some("iter-i32"))?; diff --git a/heed/src/db/uniform.rs b/heed/src/db/uniform.rs index 13a44512..e29b0398 100644 --- a/heed/src/db/uniform.rs +++ b/heed/src/db/uniform.rs @@ -21,11 +21,11 @@ use crate::*; /// use heed::{zerocopy::I64, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { -/// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; +/// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) -/// # .open(Path::new("target").join("zerocopy.mdb"))?; +/// # .open(dir.path())?; /// type BEI64 = I64; /// /// let db: Database, Unit> = env.create_database(Some("big-endian-iter"))?; @@ -68,11 +68,11 @@ use crate::*; /// use heed::{zerocopy::I64, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { -/// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; +/// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) -/// # .open(Path::new("target").join("zerocopy.mdb"))?; +/// # .open(dir.path())?; /// type BEI64 = I64; /// /// let db: Database, Unit> = env.create_database(Some("big-endian-iter"))?; @@ -136,11 +136,11 @@ impl Database { /// use heed::types::*; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// let db: Database> = env.create_database(Some("get-i32"))?; /// /// let mut wtxn = env.write_txn()?; @@ -185,11 +185,11 @@ impl Database { /// use heed::{zerocopy::U32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEU32 = U32; /// /// let db = env.create_database::, Unit>(Some("get-lt-u32"))?; @@ -240,11 +240,11 @@ impl Database { /// use heed::{zerocopy::U32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEU32 = U32; /// /// let db = env.create_database::, Unit>(Some("get-lt-u32"))?; @@ -295,11 +295,11 @@ impl Database { /// use heed::{zerocopy::U32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEU32 = U32; /// /// let db = env.create_database::, Unit>(Some("get-lt-u32"))?; @@ -350,11 +350,11 @@ impl Database { /// use heed::{zerocopy::U32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEU32 = U32; /// /// let db = env.create_database::, Unit>(Some("get-lt-u32"))?; @@ -404,11 +404,11 @@ impl Database { /// use heed::{zerocopy::I32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEI32 = I32; /// /// let db: Database, Str> = env.create_database(Some("first-i32"))?; @@ -447,11 +447,11 @@ impl Database { /// use heed::{zerocopy::I32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEI32 = I32; /// /// let db: Database, Str> = env.create_database(Some("last-i32"))?; @@ -486,11 +486,11 @@ impl Database { /// use heed::{zerocopy::I32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEI32 = I32; /// /// let db: Database, Str> = env.create_database(Some("iter-i32"))?; @@ -528,11 +528,11 @@ impl Database { /// use heed::{zerocopy::I32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEI32 = I32; /// /// let db: Database, Str> = env.create_database(Some("iter-i32"))?; @@ -570,11 +570,11 @@ impl Database { /// use heed::{zerocopy::I32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEI32 = I32; /// /// let db: Database, Str> = env.create_database(Some("iter-i32"))?; @@ -610,11 +610,11 @@ impl Database { /// use heed::{zerocopy::I32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEI32 = I32; /// /// let db: Database, Str> = env.create_database(Some("iter-i32"))?; @@ -663,11 +663,11 @@ impl Database { /// use heed::{zerocopy::I32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEI32 = I32; /// /// let db: Database, Str> = env.create_database(Some("iter-i32"))?; @@ -704,11 +704,11 @@ impl Database { /// use heed::{zerocopy::I32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEI32 = I32; /// /// let db: Database, Str> = env.create_database(Some("iter-i32"))?; @@ -762,11 +762,11 @@ impl Database { /// use heed::{zerocopy::I32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEI32 = I32; /// /// let db: Database, Str> = env.create_database(Some("iter-i32"))?; @@ -814,11 +814,11 @@ impl Database { /// use heed::{zerocopy::I32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEI32 = I32; /// /// let db: Database, Str> = env.create_database(Some("iter-i32"))?; @@ -879,11 +879,11 @@ impl Database { /// use heed::{zerocopy::I32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEI32 = I32; /// /// let db: Database, Str> = env.create_database(Some("iter-i32"))?; @@ -931,11 +931,11 @@ impl Database { /// use heed::{zerocopy::I32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEI32 = I32; /// /// let db: Database, Str> = env.create_database(Some("iter-i32"))?; @@ -996,11 +996,11 @@ impl Database { /// use heed::{zerocopy::I32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEI32 = I32; /// /// let db: Database> = env.create_database(Some("iter-i32"))?; @@ -1048,11 +1048,11 @@ impl Database { /// use heed::{zerocopy::I32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEI32 = I32; /// /// let db: Database> = env.create_database(Some("iter-i32"))?; @@ -1113,11 +1113,11 @@ impl Database { /// use heed::{zerocopy::I32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEI32 = I32; /// /// let db: Database> = env.create_database(Some("iter-i32"))?; @@ -1165,11 +1165,11 @@ impl Database { /// use heed::{zerocopy::I32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEI32 = I32; /// /// let db: Database> = env.create_database(Some("iter-i32"))?; @@ -1227,11 +1227,11 @@ impl Database { /// use heed::{zerocopy::I32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEI32 = I32; /// /// let db: Database, Str> = env.create_database(Some("iter-i32"))?; @@ -1276,11 +1276,11 @@ impl Database { /// use heed::{zerocopy::I32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEI32 = I32; /// /// let db: Database, Str> = env.create_database(Some("iter-i32"))?; @@ -1324,11 +1324,11 @@ impl Database { /// use heed::{zerocopy::I32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEI32 = I32; /// /// let db: Database, Str> = env.create_database(Some("iter-i32"))?; @@ -1377,11 +1377,11 @@ impl Database { /// use heed::{zerocopy::I32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEI32 = I32; /// /// let db: Database, Str> = env.create_database(Some("iter-i32"))?; @@ -1435,11 +1435,11 @@ impl Database { /// use heed::{zerocopy::I32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEI32 = I32; /// /// let db: Database, Str> = env.create_database(Some("iter-i32"))?; @@ -1482,11 +1482,11 @@ impl Database { /// use heed::{zerocopy::I32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEI32 = I32; /// /// let db: Database = env.create_database(Some("iter-i32"))?; @@ -1546,11 +1546,11 @@ impl Database { /// use heed::{zerocopy::I32, byteorder::BigEndian}; /// /// # fn main() -> Result<(), Box> { - /// # fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// # let dir = tempfile::tempdir()?; /// # let env = EnvOpenOptions::new() /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) - /// # .open(Path::new("target").join("zerocopy.mdb"))?; + /// # .open(dir.path())?; /// type BEI32 = I32; /// /// let db: Database, Str> = env.create_database(Some("iter-i32"))?; diff --git a/heed/src/env.rs b/heed/src/env.rs index 878229ac..cf658271 100644 --- a/heed/src/env.rs +++ b/heed/src/env.rs @@ -102,7 +102,7 @@ impl EnvOpenOptions { self } - /// Set one or more LMDB flags (see http://www.lmdb.tech/doc/group__mdb__env.html). + /// Set one or more LMDB flags (see ). /// ``` /// use std::fs; /// use std::path::Path; @@ -117,7 +117,8 @@ impl EnvOpenOptions { /// env_builder.flag(Flags::MdbNoTls); /// env_builder.flag(Flags::MdbNoMetaSync); /// } - /// let env = env_builder.open(Path::new("target").join("zerocopy.mdb"))?; + /// let dir = tempfile::tempdir().unwrap(); + /// let env = env_builder.open(dir.path())?; /// /// // we will open the default unamed database /// let db: Database> = env.create_database(None)?; @@ -526,22 +527,19 @@ impl EnvClosingEvent { #[cfg(test)] mod tests { - use std::thread; use std::time::Duration; - - use tempfile::tempdir; + use std::{fs, thread}; use crate::types::*; - use crate::{env_closing_event, EnvOpenOptions}; + use crate::{env_closing_event, EnvOpenOptions, Error}; #[test] fn close_env() { - let dir = tempdir().unwrap(); - let path = dir.path(); + let dir = tempfile::tempdir().unwrap(); let env = EnvOpenOptions::new() .map_size(10 * 1024 * 1024) // 10MB .max_dbs(30) - .open(&path) + .open(&dir.path()) .unwrap(); // Force a thread to keep the env for 1 second. @@ -558,7 +556,6 @@ mod tests { db.put(&mut wtxn, "hello", "hello").unwrap(); db.put(&mut wtxn, "world", "world").unwrap(); - // Lets check that we can prefix_iter on that sequence with the key "255". let mut iter = db.iter(&wtxn).unwrap(); assert_eq!(iter.next().transpose().unwrap(), Some(("hello", "hello"))); assert_eq!(iter.next().transpose().unwrap(), Some(("world", "world"))); @@ -574,22 +571,36 @@ mod tests { eprintln!("env closed successfully"); // Make sure we don't have a reference to the env - assert!(env_closing_event(&path).is_none()); + assert!(env_closing_event(&dir.path()).is_none()); } #[test] fn reopen_env_with_different_options_is_err() { - let dir = tempdir().unwrap(); - let path = dir.path(); + let dir = tempfile::tempdir().unwrap(); let _env = EnvOpenOptions::new() .map_size(10 * 1024 * 1024) // 10MB - .open(&path) + .open(&dir.path()) .unwrap(); - let env = EnvOpenOptions::new() - .map_size(12 * 1024 * 1024) // 10MB - .open(&path); + let result = EnvOpenOptions::new() + .map_size(12 * 1024 * 1024) // 12MB + .open(&dir.path()); + + assert!(matches!(result, Err(Error::BadOpenOptions))); + } + + #[test] + fn open_env_with_named_path() { + let dir = tempfile::tempdir().unwrap(); + fs::create_dir_all(dir.path().join("babar.mdb")).unwrap(); + let _env = EnvOpenOptions::new() + .map_size(10 * 1024 * 1024) // 10MB + .open(dir.path().join("babar.mdb")) + .unwrap(); - assert!(env.is_err()); + let _env = EnvOpenOptions::new() + .map_size(10 * 1024 * 1024) // 10MB + .open(dir.path().join("babar.mdb")) + .unwrap(); } } diff --git a/heed/src/iter/mod.rs b/heed/src/iter/mod.rs index ca6bfac5..d590186d 100644 --- a/heed/src/iter/mod.rs +++ b/heed/src/iter/mod.rs @@ -27,17 +27,14 @@ fn retreat_key(bytes: &mut Vec) { mod tests { #[test] fn prefix_iter_with_byte_255() { - use std::fs; - use std::path::Path; - use crate::types::*; use crate::EnvOpenOptions; - fs::create_dir_all(Path::new("target").join("prefix_iter_with_byte_255.mdb")).unwrap(); + let dir = tempfile::tempdir().unwrap(); let env = EnvOpenOptions::new() .map_size(10 * 1024 * 1024) // 10MB .max_dbs(3000) - .open(Path::new("target").join("prefix_iter_with_byte_255.mdb")) + .open(dir.path()) .unwrap(); let db = env.create_database::(None).unwrap(); @@ -66,19 +63,16 @@ mod tests { #[test] fn iter_last() { - use std::fs; - use std::path::Path; - use crate::byteorder::BigEndian; use crate::types::*; use crate::zerocopy::I32; use crate::EnvOpenOptions; - fs::create_dir_all(Path::new("target").join("iter_last.mdb")).unwrap(); + let dir = tempfile::tempdir().unwrap(); let env = EnvOpenOptions::new() .map_size(10 * 1024 * 1024) // 10MB .max_dbs(3000) - .open(Path::new("target").join("iter_last.mdb")) + .open(dir.path()) .unwrap(); let db = env.create_database::, Unit>(None).unwrap(); type BEI32 = I32; @@ -134,19 +128,16 @@ mod tests { #[test] fn range_iter_last() { - use std::fs; - use std::path::Path; - use crate::byteorder::BigEndian; use crate::types::*; use crate::zerocopy::I32; use crate::EnvOpenOptions; - fs::create_dir_all(Path::new("target").join("iter_last.mdb")).unwrap(); + let dir = tempfile::tempdir().unwrap(); let env = EnvOpenOptions::new() .map_size(10 * 1024 * 1024) // 10MB .max_dbs(3000) - .open(Path::new("target").join("iter_last.mdb")) + .open(dir.path()) .unwrap(); let db = env.create_database::, Unit>(None).unwrap(); type BEI32 = I32; @@ -226,17 +217,14 @@ mod tests { #[test] fn prefix_iter_last() { - use std::fs; - use std::path::Path; - use crate::types::*; use crate::EnvOpenOptions; - fs::create_dir_all(Path::new("target").join("prefix_iter_last.mdb")).unwrap(); + let dir = tempfile::tempdir().unwrap(); let env = EnvOpenOptions::new() .map_size(10 * 1024 * 1024) // 10MB .max_dbs(3000) - .open(Path::new("target").join("prefix_iter_last.mdb")) + .open(dir.path()) .unwrap(); let db = env.create_database::(None).unwrap(); @@ -301,17 +289,14 @@ mod tests { #[test] fn rev_prefix_iter_last() { - use std::fs; - use std::path::Path; - use crate::types::*; use crate::EnvOpenOptions; - fs::create_dir_all(Path::new("target").join("prefix_iter_last.mdb")).unwrap(); + let dir = tempfile::tempdir().unwrap(); let env = EnvOpenOptions::new() .map_size(10 * 1024 * 1024) // 10MB .max_dbs(3000) - .open(Path::new("target").join("prefix_iter_last.mdb")) + .open(dir.path()) .unwrap(); let db = env.create_database::(None).unwrap(); @@ -376,19 +361,16 @@ mod tests { #[test] fn rev_range_iter_last() { - use std::fs; - use std::path::Path; - use crate::byteorder::BigEndian; use crate::types::*; use crate::zerocopy::I32; use crate::EnvOpenOptions; - fs::create_dir_all(Path::new("target").join("range_iter_last.mdb")).unwrap(); + let dir = tempfile::tempdir().unwrap(); let env = EnvOpenOptions::new() .map_size(10 * 1024 * 1024) // 10MB .max_dbs(3000) - .open(Path::new("target").join("range_iter_last.mdb")) + .open(dir.path()) .unwrap(); let db = env.create_database::, Unit>(None).unwrap(); type BEI32 = I32; diff --git a/heed/src/lib.rs b/heed/src/lib.rs index 3d23eb3c..394156cd 100644 --- a/heed/src/lib.rs +++ b/heed/src/lib.rs @@ -21,8 +21,8 @@ //! use heed::types::*; //! //! # fn main() -> Result<(), Box> { -//! fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; -//! let env = EnvOpenOptions::new().open(Path::new("target").join("zerocopy.mdb"))?; +//! let dir = tempfile::tempdir()?; +//! let env = EnvOpenOptions::new().open(dir.path())?; //! //! // we will open the default unamed database //! let db: Database> = env.create_database(None)?; diff --git a/heed/src/mdb/lmdb_error.rs b/heed/src/mdb/lmdb_error.rs index 9f652447..48734221 100644 --- a/heed/src/mdb/lmdb_error.rs +++ b/heed/src/mdb/lmdb_error.rs @@ -4,7 +4,7 @@ use std::os::raw::c_char; use std::{fmt, str}; use libc::c_int; -use lmdb_sys as ffi; +use lmdb_master3_sys as ffi; /// An LMDB error kind. #[derive(Debug, Copy, Clone, Eq, PartialEq)] @@ -53,6 +53,14 @@ pub enum Error { BadValSize, /// The specified DBI was changed unexpectedly. BadDbi, + /// Unexpected problem - transaction should abort. + Problem, + /// Page checksum incorrect. + BadChecksum, + /// Encryption/decryption failed. + CryptoFail, + /// Environment encryption mismatch. + EnvEncryption, /// Other error. Other(c_int), } @@ -85,6 +93,10 @@ impl Error { ffi::MDB_BAD_TXN => Error::BadTxn, ffi::MDB_BAD_VALSIZE => Error::BadValSize, ffi::MDB_BAD_DBI => Error::BadDbi, + ffi::MDB_PROBLEM => Error::Problem, + ffi::MDB_BAD_CHECKSUM => Error::BadChecksum, + ffi::MDB_CRYPTO_FAIL => Error::CryptoFail, + ffi::MDB_ENV_ENCRYPTION => Error::EnvEncryption, other => Error::Other(other), } } @@ -113,6 +125,10 @@ impl Error { Error::BadTxn => ffi::MDB_BAD_TXN, Error::BadValSize => ffi::MDB_BAD_VALSIZE, Error::BadDbi => ffi::MDB_BAD_DBI, + Error::Problem => ffi::MDB_PROBLEM, + Error::BadChecksum => ffi::MDB_BAD_CHECKSUM, + Error::CryptoFail => ffi::MDB_CRYPTO_FAIL, + Error::EnvEncryption => ffi::MDB_ENV_ENCRYPTION, Error::Other(err_code) => err_code, } } diff --git a/heed/src/mdb/lmdb_ffi.rs b/heed/src/mdb/lmdb_ffi.rs index 8d88d07c..06bc0a88 100644 --- a/heed/src/mdb/lmdb_ffi.rs +++ b/heed/src/mdb/lmdb_ffi.rs @@ -6,7 +6,7 @@ pub use ffi::{ MDB_cursor, MDB_dbi, MDB_env, MDB_txn, MDB_APPEND, MDB_CP_COMPACT, MDB_CREATE, MDB_CURRENT, MDB_RDONLY, }; -use lmdb_sys as ffi; +use lmdb_master3_sys as ffi; pub mod cursor_op { use super::ffi::{self, MDB_cursor_op}; diff --git a/heed/src/mdb/lmdb_flags.rs b/heed/src/mdb/lmdb_flags.rs index dee6fcc1..fb7a66b5 100644 --- a/heed/src/mdb/lmdb_flags.rs +++ b/heed/src/mdb/lmdb_flags.rs @@ -1,17 +1,17 @@ -// LMDB flags (see http://www.lmdb.tech/doc/group__mdb__env.html for more details). +use lmdb_master3_sys as ffi; + +// LMDB flags (see for more details). #[repr(u32)] pub enum Flags { - MdbFixedmap = lmdb_sys::MDB_FIXEDMAP, - MdbNoSubDir = lmdb_sys::MDB_NOSUBDIR, - MdbNoSync = lmdb_sys::MDB_NOSYNC, - MdbRdOnly = lmdb_sys::MDB_RDONLY, - MdbNoMetaSync = lmdb_sys::MDB_NOMETASYNC, - MdbWriteMap = lmdb_sys::MDB_WRITEMAP, - MdbMapAsync = lmdb_sys::MDB_MAPASYNC, - MdbNoTls = lmdb_sys::MDB_NOTLS, - MdbNoLock = lmdb_sys::MDB_NOLOCK, - MdbNoRdAhead = lmdb_sys::MDB_NORDAHEAD, - MdbNoMemInit = lmdb_sys::MDB_NOMEMINIT, - /// Always free single pages instead of keeping them in a list, for future reuse. - MdbAlwaysFreePages = lmdb_sys::MDB_ALWAYSFREEPAGES, + MdbFixedmap = ffi::MDB_FIXEDMAP, + MdbNoSubDir = ffi::MDB_NOSUBDIR, + MdbNoSync = ffi::MDB_NOSYNC, + MdbRdOnly = ffi::MDB_RDONLY, + MdbNoMetaSync = ffi::MDB_NOMETASYNC, + MdbWriteMap = ffi::MDB_WRITEMAP, + MdbMapAsync = ffi::MDB_MAPASYNC, + MdbNoTls = ffi::MDB_NOTLS, + MdbNoLock = ffi::MDB_NOLOCK, + MdbNoRdAhead = ffi::MDB_NORDAHEAD, + MdbNoMemInit = ffi::MDB_NOMEMINIT, } From 994d1bd4807d4778cb796219fb7b81a300b32774 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Wed, 6 Jul 2022 15:05:18 +0200 Subject: [PATCH 03/57] Clone the LMDB submodule in the CI --- .github/workflows/test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f602afee..7c2847f1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,6 +16,8 @@ jobs: steps: - uses: actions/checkout@v2 + with: + submodules: recursive - uses: actions-rs/toolchain@v1 with: profile: minimal From cbdfd4f3b9dbaf6b34a4c21b023181a3bd491134 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Wed, 6 Jul 2022 17:12:47 +0200 Subject: [PATCH 04/57] Fix MDB_SIZE_MAX on windows platforms --- lmdb-master3-sys/bindgen.rs | 2 +- lmdb-master3-sys/src/bindings.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lmdb-master3-sys/bindgen.rs b/lmdb-master3-sys/bindgen.rs index d997757f..f602fdd3 100644 --- a/lmdb-master3-sys/bindgen.rs +++ b/lmdb-master3-sys/bindgen.rs @@ -31,7 +31,7 @@ impl ParseCallbacks for Callbacks { | "MDB_BAD_VALSIZE" | "MDB_BAD_DBI" | "MDB_LAST_ERRCODE" => Some(IntKind::Int), - "MDB_SIZE_MAX" => Some(IntKind::ULong), + "MDB_SIZE_MAX" => Some(IntKind::U64), "MDB_PROBLEM" | "MDB_BAD_CHECKSUM" | "MDB_CRYPTO_FAIL" | "MDB_ENV_ENCRYPTION" => { Some(IntKind::Int) } diff --git a/lmdb-master3-sys/src/bindings.rs b/lmdb-master3-sys/src/bindings.rs index 3d6af196..8cb8318d 100644 --- a/lmdb-master3-sys/src/bindings.rs +++ b/lmdb-master3-sys/src/bindings.rs @@ -2,7 +2,7 @@ pub const MDB_FMT_Z: &'static [u8; 2usize] = b"z\0"; pub const MDB_RPAGE_CACHE: ::libc::c_uint = 1; -pub const MDB_SIZE_MAX: ::libc::c_ulong = 18446744073709551615; +pub const MDB_SIZE_MAX: u64 = 18446744073709551615; pub const MDB_VERSION_MAJOR: ::libc::c_uint = 0; pub const MDB_VERSION_MINOR: ::libc::c_uint = 9; pub const MDB_VERSION_PATCH: ::libc::c_uint = 90; From 7602a9f40b3f4d9268349b4ce3786ad9d22c8759 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Sat, 16 Jan 2021 12:35:08 +0100 Subject: [PATCH 05/57] Copycat and modify the zerocopy integer types contructors --- Fushia_LICENSE | 24 +++ heed-types/Cargo.toml | 6 +- heed-types/src/integer.rs | 337 +++++++++++++++++++++++++++++++++++++ heed-types/src/lib.rs | 2 + heed/examples/all-types.rs | 12 +- heed/src/db/uniform.rs | 56 +++--- 6 files changed, 406 insertions(+), 31 deletions(-) create mode 100644 Fushia_LICENSE create mode 100644 heed-types/src/integer.rs diff --git a/Fushia_LICENSE b/Fushia_LICENSE new file mode 100644 index 00000000..7ed244f4 --- /dev/null +++ b/Fushia_LICENSE @@ -0,0 +1,24 @@ +Copyright 2019 The Fuchsia Authors. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/heed-types/Cargo.toml b/heed-types/Cargo.toml index 541b5bbd..99309edf 100644 --- a/heed-types/Cargo.toml +++ b/heed-types/Cargo.toml @@ -10,10 +10,14 @@ edition = "2018" [dependencies] bincode = { version = "1.2.1", optional = true } +bytemuck = { version = "1.5.0", features = ["extern_crate_alloc"] } +byteorder = "1.4.2" heed-traits = { version = "0.7.0", path = "../heed-traits" } serde = { version = "1.0.117", optional = true } serde_json = { version = "1.0.59", optional = true } -zerocopy = "0.3.0" + +[dev-dependencies] +rand = "0.8.2" [features] default = ["serde-bincode", "serde-json"] diff --git a/heed-types/src/integer.rs b/heed-types/src/integer.rs new file mode 100644 index 00000000..c5ec8b11 --- /dev/null +++ b/heed-types/src/integer.rs @@ -0,0 +1,337 @@ +// Copyright 2019 The Fuchsia Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the Fushia_LICENSE file. + +//! Byte order-aware numeric primitives. +//! +//! This module contains equivalents of the native multi-byte integer types with +//! no alignment requirement and supporting byte order conversions. +//! +//! For each native multi-byte integer type - `u16`, `i16`, `u32`, etc - an +//! equivalent type is defined by this module - [`U16`], [`I16`], [`U32`], etc. +//! Unlike their native counterparts, these types have alignment 1, and take a +//! type parameter specifying the byte order in which the bytes are stored in +//! memory. Each type implements the [`Zeroable`], and [`Pod`] traits. +//! +//! These two properties, taken together, make these types very useful for +//! defining data structures whose memory layout matches a wire format such as +//! that of a network protocol or a file format. Such formats often have +//! multi-byte values at offsets that do not respect the alignment requirements +//! of the equivalent native types, and stored in a byte order not necessarily +//! the same as that of the target platform. + +use std::fmt::{self, Binary, Debug, Display, Formatter, LowerHex, Octal, UpperHex}; +use std::marker::PhantomData; + +use bytemuck::{Zeroable, Pod}; +use byteorder::ByteOrder; + +macro_rules! impl_fmt_trait { + ($name:ident, $native:ident, $trait:ident) => { + impl $trait for $name { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + $trait::fmt(&self.get(), f) + } + } + }; +} + +macro_rules! doc_comment { + ($x:expr, $($tt:tt)*) => { + #[doc = $x] + $($tt)* + }; +} + +macro_rules! define_type { + ($article:ident, $name:ident, $native:ident, $bits:expr, $bytes:expr, $read_method:ident, $write_method:ident, $sign:ident) => { + doc_comment! { + concat!("A ", stringify!($bits), "-bit ", stringify!($sign), " integer +stored in `O` byte order. + +`", stringify!($name), "` is like the native `", stringify!($native), "` type with +two major differences: First, it has no alignment requirement (its alignment is 1). +Second, the endianness of its memory layout is given by the type parameter `O`. + +", stringify!($article), " `", stringify!($name), "` can be constructed using +the [`new`] method, and its contained value can be obtained as a native +`",stringify!($native), "` using the [`get`] method, or updated in place with +the [`set`] method. In all cases, if the endianness `O` is not the same as the +endianness of the current platform, an endianness swap will be performed in +order to uphold the invariants that a) the layout of `", stringify!($name), "` +has endianness `O` and that, b) the layout of `", stringify!($native), "` has +the platform's native endianness. + +`", stringify!($name), "` implements [`Zeroable`], and [`Pod`], +making it useful for parsing and serialization. + +[`new`]: crate::byteorder::", stringify!($name), "::new +[`get`]: crate::byteorder::", stringify!($name), "::get +[`set`]: crate::byteorder::", stringify!($name), "::set +[`Zeroable`]: bytemuck::Zeroable +[`Pod`]: bytemuck::Pod"), + #[derive(Default, Copy, Clone, Eq, PartialEq, Hash)] + #[repr(transparent)] + pub struct $name([u8; $bytes], PhantomData); + } + + unsafe impl Zeroable for $name { + fn zeroed() -> $name { + $name([0u8; $bytes], PhantomData) + } + } + + unsafe impl Pod for $name {} + + impl $name { + // TODO(joshlf): Make these const fns if the ByteOrder methods ever + // become const fns. + + /// Constructs a new value, possibly performing an endianness swap + /// to guarantee that the returned value has endianness `O`. + pub fn new(n: $native) -> $name { + let mut out = $name::default(); + O::$write_method(&mut out.0[..], n); + out + } + + /// Returns the value as a primitive type, possibly performing an + /// endianness swap to guarantee that the return value has the + /// endianness of the native platform. + pub fn get(self) -> $native { + O::$read_method(&self.0[..]) + } + + /// Updates the value in place as a primitive type, possibly + /// performing an endianness swap to guarantee that the stored value + /// has the endianness `O`. + pub fn set(&mut self, n: $native) { + O::$write_method(&mut self.0[..], n); + } + } + + // NOTE: The reasoning behind which traits to implement here is a) only + // implement traits which do not involve implicit endianness swaps and, + // b) only implement traits which won't cause inference issues. Most of + // the traits which would cause inference issues would also involve + // endianness swaps anyway (like comparison/ordering with the native + // representation or conversion from/to that representation). Note that + // we make an exception for the format traits since the cost of + // formatting dwarfs cost of performing an endianness swap, and they're + // very useful. + + impl From<$name> for [u8; $bytes] { + fn from(x: $name) -> [u8; $bytes] { + x.0 + } + } + + impl From<[u8; $bytes]> for $name { + fn from(bytes: [u8; $bytes]) -> $name { + $name(bytes, PhantomData) + } + } + + impl AsRef<[u8; $bytes]> for $name { + fn as_ref(&self) -> &[u8; $bytes] { + &self.0 + } + } + + impl AsMut<[u8; $bytes]> for $name { + fn as_mut(&mut self) -> &mut [u8; $bytes] { + &mut self.0 + } + } + + impl PartialEq<$name> for [u8; $bytes] { + fn eq(&self, other: &$name) -> bool { + self.eq(&other.0) + } + } + + impl PartialEq<[u8; $bytes]> for $name { + fn eq(&self, other: &[u8; $bytes]) -> bool { + self.0.eq(other) + } + } + + impl_fmt_trait!($name, $native, Display); + impl_fmt_trait!($name, $native, Octal); + impl_fmt_trait!($name, $native, LowerHex); + impl_fmt_trait!($name, $native, UpperHex); + impl_fmt_trait!($name, $native, Binary); + + impl Debug for $name { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + // This results in a format like "U16(42)" + write!(f, concat!(stringify!($name), "({})"), self.get()) + } + } + }; +} + +define_type!(A, U16, u16, 16, 2, read_u16, write_u16, unsigned); +define_type!(A, U32, u32, 32, 4, read_u32, write_u32, unsigned); +define_type!(A, U64, u64, 64, 8, read_u64, write_u64, unsigned); +define_type!(A, U128, u128, 128, 16, read_u128, write_u128, unsigned); +define_type!(An, I16, i16, 16, 2, read_i16, write_i16, signed); +define_type!(An, I32, i32, 32, 4, read_i32, write_i32, signed); +define_type!(An, I64, i64, 64, 8, read_i64, write_i64, signed); +define_type!(An, I128, i128, 128, 16, read_i128, write_i128, signed); + +#[cfg(test)] +mod tests { + use byteorder::NativeEndian; + use bytemuck::{Pod, bytes_of, bytes_of_mut}; + + use super::*; + + // A native integer type (u16, i32, etc) + trait Native: Pod + Copy + Eq + Debug { + fn rand() -> Self; + } + + trait ByteArray: Pod + Copy + AsRef<[u8]> + AsMut<[u8]> + Debug + Default + Eq { + /// Invert the order of the bytes in the array. + fn invert(self) -> Self; + } + + trait ByteOrderType: Pod + Copy + Eq + Debug { + type Native: Native; + type ByteArray: ByteArray; + + fn new(native: Self::Native) -> Self; + fn get(self) -> Self::Native; + fn set(&mut self, native: Self::Native); + fn from_bytes(bytes: Self::ByteArray) -> Self; + fn into_bytes(self) -> Self::ByteArray; + } + + macro_rules! impl_byte_array { + ($bytes:expr) => { + impl ByteArray for [u8; $bytes] { + fn invert(mut self) -> [u8; $bytes] { + self.reverse(); + self + } + } + }; + } + + impl_byte_array!(2); + impl_byte_array!(4); + impl_byte_array!(8); + impl_byte_array!(16); + + macro_rules! impl_traits { + ($name:ident, $native:ident, $bytes:expr, $sign:ident) => { + impl Native for $native { + fn rand() -> $native { + rand::random() + } + } + + impl ByteOrderType for $name { + type Native = $native; + type ByteArray = [u8; $bytes]; + + fn new(native: $native) -> $name { + $name::new(native) + } + + fn get(self) -> $native { + $name::get(self) + } + + fn set(&mut self, native: $native) { + $name::set(self, native) + } + + fn from_bytes(bytes: [u8; $bytes]) -> $name { + $name::from(bytes) + } + + fn into_bytes(self) -> [u8; $bytes] { + <[u8; $bytes]>::from(self) + } + } + }; + } + + impl_traits!(U16, u16, 2, unsigned); + impl_traits!(U32, u32, 4, unsigned); + impl_traits!(U64, u64, 8, unsigned); + impl_traits!(U128, u128, 16, unsigned); + impl_traits!(I16, i16, 2, signed); + impl_traits!(I32, i32, 4, signed); + impl_traits!(I64, i64, 8, signed); + impl_traits!(I128, i128, 16, signed); + + macro_rules! call_for_all_types { + ($fn:ident, $byteorder:ident) => { + $fn::>(); + $fn::>(); + $fn::>(); + $fn::>(); + $fn::>(); + $fn::>(); + $fn::>(); + $fn::>(); + }; + } + + #[cfg(target_endian = "big")] + type NonNativeEndian = byteorder::LittleEndian; + #[cfg(target_endian = "little")] + type NonNativeEndian = byteorder::BigEndian; + + #[test] + fn test_native_endian() { + fn test_native_endian() { + for _ in 0..1024 { + let native = T::Native::rand(); + let mut bytes = T::ByteArray::default(); + bytes_of_mut(&mut bytes).copy_from_slice(bytes_of(&native)); + let mut from_native = T::new(native); + let from_bytes = T::from_bytes(bytes); + assert_eq!(from_native, from_bytes); + assert_eq!(from_native.get(), native); + assert_eq!(from_bytes.get(), native); + assert_eq!(from_native.into_bytes(), bytes); + assert_eq!(from_bytes.into_bytes(), bytes); + + let updated = T::Native::rand(); + from_native.set(updated); + assert_eq!(from_native.get(), updated); + } + } + + call_for_all_types!(test_native_endian, NativeEndian); + } + + #[test] + fn test_non_native_endian() { + fn test_non_native_endian() { + for _ in 0..1024 { + let native = T::Native::rand(); + let mut bytes = T::ByteArray::default(); + bytes_of_mut(&mut bytes).copy_from_slice(bytes_of(&native)); + bytes = bytes.invert(); + let mut from_native = T::new(native); + let from_bytes = T::from_bytes(bytes); + assert_eq!(from_native, from_bytes); + assert_eq!(from_native.get(), native); + assert_eq!(from_bytes.get(), native); + assert_eq!(from_native.into_bytes(), bytes); + assert_eq!(from_bytes.into_bytes(), bytes); + + let updated = T::Native::rand(); + from_native.set(updated); + assert_eq!(from_native.get(), updated); + } + } + + call_for_all_types!(test_non_native_endian, NonNativeEndian); + } +} diff --git a/heed-types/src/lib.rs b/heed-types/src/lib.rs index d1ee0c8e..ed1b8ba9 100644 --- a/heed-types/src/lib.rs +++ b/heed-types/src/lib.rs @@ -40,6 +40,7 @@ mod str; mod unaligned_slice; mod unaligned_type; mod unit; +pub mod integer; #[cfg(feature = "serde-bincode")] mod serde_bincode; @@ -49,6 +50,7 @@ mod serde_json; pub use self::cow_slice::CowSlice; pub use self::cow_type::CowType; +pub use self::integer::*; pub use self::owned_slice::OwnedSlice; pub use self::owned_type::OwnedType; pub use self::str::Str; diff --git a/heed/examples/all-types.rs b/heed/examples/all-types.rs index c9e43951..55361f23 100644 --- a/heed/examples/all-types.rs +++ b/heed/examples/all-types.rs @@ -4,7 +4,7 @@ use std::path::Path; use heed::byteorder::BE; use heed::types::*; -use heed::zerocopy::{AsBytes, FromBytes, Unaligned, I64}; +use heed::bytemuck::{Pod, Zeroable}; use heed::{Database, EnvOpenOptions}; use serde::{Deserialize, Serialize}; @@ -72,12 +72,20 @@ fn main() -> Result<(), Box> { wtxn.commit()?; // it is prefered to use zerocopy when possible - #[derive(Debug, PartialEq, Eq, AsBytes, FromBytes, Unaligned)] + #[derive(Debug, Clone, Copy, PartialEq, Eq)] #[repr(C)] struct ZeroBytes { bytes: [u8; 12], } + unsafe impl Zeroable for ZeroBytes { + fn zeroed() -> Self { + ZeroBytes { bytes: Default::default() } + } + } + + unsafe impl Pod for ZeroBytes { } + let db: Database> = env.create_database(Some("zerocopy-struct"))?; diff --git a/heed/src/db/uniform.rs b/heed/src/db/uniform.rs index e29b0398..0c175425 100644 --- a/heed/src/db/uniform.rs +++ b/heed/src/db/uniform.rs @@ -18,7 +18,7 @@ use crate::*; /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; -/// use heed::{zerocopy::I64, byteorder::BigEndian}; +/// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -65,7 +65,7 @@ use crate::*; /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; -/// use heed::{zerocopy::I64, byteorder::BigEndian}; +/// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -182,7 +182,7 @@ impl Database { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; - /// use heed::{zerocopy::U32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -237,7 +237,7 @@ impl Database { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; - /// use heed::{zerocopy::U32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -292,7 +292,7 @@ impl Database { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; - /// use heed::{zerocopy::U32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -347,7 +347,7 @@ impl Database { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; - /// use heed::{zerocopy::U32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -401,7 +401,7 @@ impl Database { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; - /// use heed::{zerocopy::I32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -444,7 +444,7 @@ impl Database { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; - /// use heed::{zerocopy::I32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -483,7 +483,7 @@ impl Database { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; - /// use heed::{zerocopy::I32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -525,7 +525,7 @@ impl Database { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; - /// use heed::{zerocopy::I32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -567,7 +567,7 @@ impl Database { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; - /// use heed::{zerocopy::I32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -607,7 +607,7 @@ impl Database { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; - /// use heed::{zerocopy::I32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -660,7 +660,7 @@ impl Database { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; - /// use heed::{zerocopy::I32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -701,7 +701,7 @@ impl Database { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; - /// use heed::{zerocopy::I32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -759,7 +759,7 @@ impl Database { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; - /// use heed::{zerocopy::I32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -811,7 +811,7 @@ impl Database { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; - /// use heed::{zerocopy::I32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -876,7 +876,7 @@ impl Database { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; - /// use heed::{zerocopy::I32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -928,7 +928,7 @@ impl Database { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; - /// use heed::{zerocopy::I32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -993,7 +993,7 @@ impl Database { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; - /// use heed::{zerocopy::I32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -1045,7 +1045,7 @@ impl Database { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; - /// use heed::{zerocopy::I32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -1110,7 +1110,7 @@ impl Database { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; - /// use heed::{zerocopy::I32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -1162,7 +1162,7 @@ impl Database { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; - /// use heed::{zerocopy::I32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -1224,7 +1224,7 @@ impl Database { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; - /// use heed::{zerocopy::I32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -1273,7 +1273,7 @@ impl Database { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; - /// use heed::{zerocopy::I32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -1321,7 +1321,7 @@ impl Database { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; - /// use heed::{zerocopy::I32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -1374,7 +1374,7 @@ impl Database { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; - /// use heed::{zerocopy::I32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -1432,7 +1432,7 @@ impl Database { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; - /// use heed::{zerocopy::I32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -1479,7 +1479,7 @@ impl Database { /// # use heed::EnvOpenOptions; /// use heed::{Database, PolyDatabase}; /// use heed::types::*; - /// use heed::{zerocopy::I32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; From aacd1e954b7c557e32a7baea3fb9180ab3266c9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Mon, 18 Jan 2021 16:29:39 +0100 Subject: [PATCH 06/57] Use bytemuck 1.5.0 in heed --- Fushia_LICENSE => Fuchsia_LICENSE | 0 README.md | 2 +- heed-types/src/cow_slice.rs | 44 +++++------------------- heed-types/src/cow_type.rs | 43 ++++++------------------ heed-types/src/integer.rs | 10 +++--- heed-types/src/lib.rs | 17 +--------- heed-types/src/owned_slice.rs | 14 +++----- heed-types/src/owned_type.rs | 14 +++----- heed-types/src/str.rs | 6 ++-- heed-types/src/unaligned_slice.rs | 16 +++------ heed-types/src/unaligned_type.rs | 16 +++------ heed/Cargo.toml | 3 +- heed/examples/all-types-poly.rs | 7 ++-- heed/examples/all-types.rs | 17 +++------- heed/src/db/polymorph.rs | 56 +++++++++++++++---------------- heed/src/db/uniform.rs | 2 +- heed/src/env.rs | 4 +-- heed/src/iter/mod.rs | 3 -- heed/src/lib.rs | 6 ++-- 19 files changed, 89 insertions(+), 191 deletions(-) rename Fushia_LICENSE => Fuchsia_LICENSE (100%) diff --git a/Fushia_LICENSE b/Fuchsia_LICENSE similarity index 100% rename from Fushia_LICENSE rename to Fuchsia_LICENSE diff --git a/README.md b/README.md index 9370a533..529f44ef 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # heed -A fully typed [LMDB](https://en.wikipedia.org/wiki/Lightning_Memory-Mapped_Database) wrapper with minimum overhead, uses zerocopy internally. +A fully typed [LMDB](https://en.wikipedia.org/wiki/Lightning_Memory-Mapped_Database) wrapper with minimum overhead, uses bytemuck internally. [![License](https://img.shields.io/badge/license-MIT-green)](#LICENSE) [![Crates.io](https://img.shields.io/crates/v/heed)](https://crates.io/crates/heed) diff --git a/heed-types/src/cow_slice.rs b/heed-types/src/cow_slice.rs index a13341c2..64d161a6 100644 --- a/heed-types/src/cow_slice.rs +++ b/heed-types/src/cow_slice.rs @@ -1,10 +1,7 @@ use std::borrow::Cow; -use std::{mem, ptr}; +use bytemuck::{pod_collect_to_vec, try_cast_slice, AnyBitPattern, NoUninit, PodCastError}; use heed_traits::{BytesDecode, BytesEncode}; -use zerocopy::{AsBytes, FromBytes, LayoutVerified}; - -use crate::aligned_to; /// Describes a slice that must be [memory aligned] and /// will be reallocated if it is not. @@ -23,47 +20,22 @@ use crate::aligned_to; /// [`OwnedSlice`]: crate::OwnedSlice pub struct CowSlice(std::marker::PhantomData); -impl<'a, T: 'a> BytesEncode<'a> for CowSlice -where - T: AsBytes, -{ +impl<'a, T: NoUninit> BytesEncode<'a> for CowSlice { type EItem = [T]; fn bytes_encode(item: &'a Self::EItem) -> Option> { - Some(Cow::Borrowed(<[T] as AsBytes>::as_bytes(item))) + try_cast_slice(item).map(Cow::Borrowed).ok() } } -impl<'a, T: 'a> BytesDecode<'a> for CowSlice -where - T: FromBytes + Copy, -{ +impl<'a, T: AnyBitPattern + NoUninit> BytesDecode<'a> for CowSlice { type DItem = Cow<'a, [T]>; fn bytes_decode(bytes: &'a [u8]) -> Option { - match LayoutVerified::<_, [T]>::new_slice(bytes) { - Some(layout) => Some(Cow::Borrowed(layout.into_slice())), - None => { - let len = bytes.len(); - let elem_size = mem::size_of::(); - - // ensure that it is the alignment that is wrong - // and the length is valid - if len % elem_size == 0 && !aligned_to(bytes, mem::align_of::()) { - let elems = len / elem_size; - let mut vec = Vec::::with_capacity(elems); - - unsafe { - let dst = vec.as_mut_ptr() as *mut u8; - ptr::copy_nonoverlapping(bytes.as_ptr(), dst, len); - vec.set_len(elems); - } - - return Some(Cow::Owned(vec)); - } - - None - } + match try_cast_slice(bytes) { + Ok(items) => Some(Cow::Borrowed(items)), + Err(PodCastError::AlignmentMismatch) => Some(Cow::Owned(pod_collect_to_vec(bytes))), + Err(_) => None, } } } diff --git a/heed-types/src/cow_type.rs b/heed-types/src/cow_type.rs index 4ace47b5..8282dfb7 100644 --- a/heed-types/src/cow_type.rs +++ b/heed-types/src/cow_type.rs @@ -1,10 +1,7 @@ use std::borrow::Cow; -use std::{mem, ptr}; +use bytemuck::{bytes_of, bytes_of_mut, try_from_bytes, AnyBitPattern, NoUninit, PodCastError}; use heed_traits::{BytesDecode, BytesEncode}; -use zerocopy::{AsBytes, FromBytes, LayoutVerified}; - -use crate::aligned_to; /// Describes a type that must be [memory aligned] and /// will be reallocated if it is not. @@ -29,44 +26,26 @@ use crate::aligned_to; /// [`CowSlice`]: crate::CowSlice pub struct CowType(std::marker::PhantomData); -impl<'a, T: 'a> BytesEncode<'a> for CowType -where - T: AsBytes, -{ +impl<'a, T: NoUninit> BytesEncode<'a> for CowType { type EItem = T; fn bytes_encode(item: &'a Self::EItem) -> Option> { - Some(Cow::Borrowed(::as_bytes(item))) + Some(Cow::Borrowed(bytes_of(item))) } } -impl<'a, T: 'a> BytesDecode<'a> for CowType -where - T: FromBytes + Copy, -{ +impl<'a, T: AnyBitPattern + NoUninit> BytesDecode<'a> for CowType { type DItem = Cow<'a, T>; fn bytes_decode(bytes: &'a [u8]) -> Option { - match LayoutVerified::<_, T>::new(bytes) { - Some(layout) => Some(Cow::Borrowed(layout.into_ref())), - None => { - let len = bytes.len(); - let elem_size = mem::size_of::(); - - // ensure that it is the alignment that is wrong - // and the length is valid - if len == elem_size && !aligned_to(bytes, mem::align_of::()) { - let mut data = mem::MaybeUninit::::uninit(); - - unsafe { - let dst = data.as_mut_ptr() as *mut u8; - ptr::copy_nonoverlapping(bytes.as_ptr(), dst, len); - return Some(Cow::Owned(data.assume_init())); - } - } - - None + match try_from_bytes(bytes) { + Ok(item) => Some(Cow::Borrowed(item)), + Err(PodCastError::TargetAlignmentGreaterAndInputNotAligned) => { + let mut item = T::zeroed(); + bytes_of_mut(&mut item).copy_from_slice(bytes); + Some(Cow::Owned(item)) } + Err(_) => None, } } } diff --git a/heed-types/src/integer.rs b/heed-types/src/integer.rs index c5ec8b11..24e76410 100644 --- a/heed-types/src/integer.rs +++ b/heed-types/src/integer.rs @@ -23,7 +23,7 @@ use std::fmt::{self, Binary, Debug, Display, Formatter, LowerHex, Octal, UpperHex}; use std::marker::PhantomData; -use bytemuck::{Zeroable, Pod}; +use bytemuck::{Pod, Zeroable}; use byteorder::ByteOrder; macro_rules! impl_fmt_trait { @@ -65,9 +65,9 @@ the platform's native endianness. `", stringify!($name), "` implements [`Zeroable`], and [`Pod`], making it useful for parsing and serialization. -[`new`]: crate::byteorder::", stringify!($name), "::new -[`get`]: crate::byteorder::", stringify!($name), "::get -[`set`]: crate::byteorder::", stringify!($name), "::set +[`new`]: crate::integer::", stringify!($name), "::new +[`get`]: crate::integer::", stringify!($name), "::get +[`set`]: crate::integer::", stringify!($name), "::set [`Zeroable`]: bytemuck::Zeroable [`Pod`]: bytemuck::Pod"), #[derive(Default, Copy, Clone, Eq, PartialEq, Hash)] @@ -182,8 +182,8 @@ define_type!(An, I128, i128, 128, 16, read_i128, write_i128, signed); #[cfg(test)] mod tests { + use bytemuck::{bytes_of, bytes_of_mut, Pod}; use byteorder::NativeEndian; - use bytemuck::{Pod, bytes_of, bytes_of_mut}; use super::*; diff --git a/heed-types/src/lib.rs b/heed-types/src/lib.rs index ed1b8ba9..b65ce519 100644 --- a/heed-types/src/lib.rs +++ b/heed-types/src/lib.rs @@ -18,29 +18,18 @@ //! | [`UnalignedSlice`] | `&[T]` | `&[T]` | will _never_ allocate because alignement is always valid | //! | [`UnalignedType`] | `&T` | `&T` | will _never_ allocate because alignement is always valid | //! -//! Note that **all** those types above must implement [`AsBytes`] and [`FromBytes`].
-//! The `UnalignedSlice/Type` types also need to implement the [`Unaligned`] trait. -//! -//! If you don't want to/cannot deal with `AsBytes`, `Frombytes` or `Unaligned` requirements -//! we recommend you to use the `SerdeBincode` or `SerdeJson` types and deal with the `Serialize`/`Deserialize` traits. -//! -//! [`AsBytes`]: zerocopy::AsBytes -//! [`FromBytes`]: zerocopy::FromBytes -//! [`Unaligned`]: zerocopy::Unaligned -//! //! [`Serialize`]: serde::Serialize //! [`Deserialize`]: serde::Deserialize -//! mod cow_slice; mod cow_type; +mod integer; mod owned_slice; mod owned_type; mod str; mod unaligned_slice; mod unaligned_type; mod unit; -pub mod integer; #[cfg(feature = "serde-bincode")] mod serde_bincode; @@ -82,7 +71,3 @@ impl heed_traits::BytesDecode<'_> for DecodeIgnore { pub use self::serde_bincode::SerdeBincode; #[cfg(feature = "serde-json")] pub use self::serde_json::SerdeJson; - -fn aligned_to(bytes: &[u8], align: usize) -> bool { - (bytes as *const _ as *const () as usize) % align == 0 -} diff --git a/heed-types/src/owned_slice.rs b/heed-types/src/owned_slice.rs index c1914260..c566f436 100644 --- a/heed-types/src/owned_slice.rs +++ b/heed-types/src/owned_slice.rs @@ -1,7 +1,7 @@ use std::borrow::Cow; +use bytemuck::{try_cast_slice, AnyBitPattern, NoUninit}; use heed_traits::{BytesDecode, BytesEncode}; -use zerocopy::{AsBytes, FromBytes}; use crate::CowSlice; @@ -20,21 +20,15 @@ use crate::CowSlice; /// [`CowType`]: crate::CowType pub struct OwnedSlice(std::marker::PhantomData); -impl<'a, T: 'a> BytesEncode<'a> for OwnedSlice -where - T: AsBytes, -{ +impl<'a, T: NoUninit> BytesEncode<'a> for OwnedSlice { type EItem = [T]; fn bytes_encode(item: &'a Self::EItem) -> Option> { - Some(Cow::Borrowed(<[T] as AsBytes>::as_bytes(item))) + try_cast_slice(item).map(Cow::Borrowed).ok() } } -impl<'a, T: 'a> BytesDecode<'a> for OwnedSlice -where - T: FromBytes + Copy, -{ +impl<'a, T: AnyBitPattern + NoUninit> BytesDecode<'a> for OwnedSlice { type DItem = Vec; fn bytes_decode(bytes: &[u8]) -> Option { diff --git a/heed-types/src/owned_type.rs b/heed-types/src/owned_type.rs index 349190f2..a88bc0e1 100644 --- a/heed-types/src/owned_type.rs +++ b/heed-types/src/owned_type.rs @@ -1,7 +1,7 @@ use std::borrow::Cow; +use bytemuck::{bytes_of, AnyBitPattern, NoUninit}; use heed_traits::{BytesDecode, BytesEncode}; -use zerocopy::{AsBytes, FromBytes}; use crate::CowType; @@ -26,21 +26,15 @@ use crate::CowType; /// [`CowSlice`]: crate::CowSlice pub struct OwnedType(std::marker::PhantomData); -impl<'a, T: 'a> BytesEncode<'a> for OwnedType -where - T: AsBytes, -{ +impl<'a, T: NoUninit> BytesEncode<'a> for OwnedType { type EItem = T; fn bytes_encode(item: &'a Self::EItem) -> Option> { - Some(Cow::Borrowed(::as_bytes(item))) + Some(Cow::Borrowed(bytes_of(item))) } } -impl<'a, T: 'a> BytesDecode<'a> for OwnedType -where - T: FromBytes + Copy, -{ +impl<'a, T: AnyBitPattern + NoUninit> BytesDecode<'a> for OwnedType { type DItem = T; fn bytes_decode(bytes: &[u8]) -> Option { diff --git a/heed-types/src/str.rs b/heed-types/src/str.rs index 5b110775..9c40c542 100644 --- a/heed-types/src/str.rs +++ b/heed-types/src/str.rs @@ -2,16 +2,14 @@ use std::borrow::Cow; use heed_traits::{BytesDecode, BytesEncode}; -use crate::UnalignedSlice; - -/// Describes an [`str`]. +/// Describes an [`prim@str`]. pub struct Str; impl BytesEncode<'_> for Str { type EItem = str; fn bytes_encode(item: &Self::EItem) -> Option> { - UnalignedSlice::::bytes_encode(item.as_bytes()) + Some(Cow::Borrowed(item.as_bytes())) } } diff --git a/heed-types/src/unaligned_slice.rs b/heed-types/src/unaligned_slice.rs index b5b1b11a..3ab36943 100644 --- a/heed-types/src/unaligned_slice.rs +++ b/heed-types/src/unaligned_slice.rs @@ -1,7 +1,7 @@ use std::borrow::Cow; +use bytemuck::{try_cast_slice, AnyBitPattern, NoUninit}; use heed_traits::{BytesDecode, BytesEncode}; -use zerocopy::{AsBytes, FromBytes, LayoutVerified, Unaligned}; /// Describes a type that is totally borrowed and doesn't /// depends on any [memory alignment]. @@ -13,25 +13,19 @@ use zerocopy::{AsBytes, FromBytes, LayoutVerified, Unaligned}; /// [`CowType`]: crate::CowType pub struct UnalignedSlice(std::marker::PhantomData); -impl<'a, T: 'a> BytesEncode<'a> for UnalignedSlice -where - T: AsBytes + Unaligned, -{ +impl<'a, T: NoUninit> BytesEncode<'a> for UnalignedSlice { type EItem = [T]; fn bytes_encode(item: &'a Self::EItem) -> Option> { - Some(Cow::Borrowed(<[T] as AsBytes>::as_bytes(item))) + try_cast_slice(item).map(Cow::Borrowed).ok() } } -impl<'a, T: 'a> BytesDecode<'a> for UnalignedSlice -where - T: FromBytes + Unaligned, -{ +impl<'a, T: AnyBitPattern> BytesDecode<'a> for UnalignedSlice { type DItem = &'a [T]; fn bytes_decode(bytes: &'a [u8]) -> Option { - LayoutVerified::<_, [T]>::new_slice_unaligned(bytes).map(LayoutVerified::into_slice) + try_cast_slice(bytes).ok() } } diff --git a/heed-types/src/unaligned_type.rs b/heed-types/src/unaligned_type.rs index a87fdb08..f2756a9b 100644 --- a/heed-types/src/unaligned_type.rs +++ b/heed-types/src/unaligned_type.rs @@ -1,7 +1,7 @@ use std::borrow::Cow; +use bytemuck::{bytes_of, try_from_bytes, AnyBitPattern, NoUninit}; use heed_traits::{BytesDecode, BytesEncode}; -use zerocopy::{AsBytes, FromBytes, LayoutVerified, Unaligned}; /// Describes a slice that is totally borrowed and doesn't /// depends on any [memory alignment]. @@ -19,25 +19,19 @@ use zerocopy::{AsBytes, FromBytes, LayoutVerified, Unaligned}; /// [`CowSlice`]: crate::CowSlice pub struct UnalignedType(std::marker::PhantomData); -impl<'a, T: 'a> BytesEncode<'a> for UnalignedType -where - T: AsBytes + Unaligned, -{ +impl<'a, T: NoUninit> BytesEncode<'a> for UnalignedType { type EItem = T; fn bytes_encode(item: &'a Self::EItem) -> Option> { - Some(Cow::Borrowed(::as_bytes(item))) + Some(Cow::Borrowed(bytes_of(item))) } } -impl<'a, T: 'a> BytesDecode<'a> for UnalignedType -where - T: FromBytes + Unaligned, -{ +impl<'a, T: AnyBitPattern> BytesDecode<'a> for UnalignedType { type DItem = &'a T; fn bytes_decode(bytes: &'a [u8]) -> Option { - LayoutVerified::<_, T>::new_unaligned(bytes).map(LayoutVerified::into_ref) + try_from_bytes(bytes).ok() } } diff --git a/heed/Cargo.toml b/heed/Cargo.toml index 75239b16..4f592d7f 100644 --- a/heed/Cargo.toml +++ b/heed/Cargo.toml @@ -11,6 +11,7 @@ readme = "../README.md" edition = "2018" [dependencies] +bytemuck = "1.5.0" byteorder = { version = "1.3.4", default-features = false } heed-traits = { version = "0.7.0", path = "../heed-traits" } heed-types = { version = "0.7.2", path = "../heed-types" } @@ -20,10 +21,10 @@ once_cell = "1.5.2" page_size = "0.4.2" serde = { version = "1.0.118", features = ["derive"], optional = true } synchronoise = "1.0.0" -zerocopy = "0.3.0" [dev-dependencies] serde = { version = "1.0.118", features = ["derive"] } +bytemuck = { version = "1.5.0", features = ["derive"] } tempfile = "3.3.0" [target.'cfg(windows)'.dependencies] diff --git a/heed/examples/all-types-poly.rs b/heed/examples/all-types-poly.rs index f55aa947..edba1168 100644 --- a/heed/examples/all-types-poly.rs +++ b/heed/examples/all-types-poly.rs @@ -2,9 +2,9 @@ use std::error::Error; use std::fs; use std::path::Path; +use bytemuck::{Pod, Zeroable}; use heed::byteorder::BE; use heed::types::*; -use heed::zerocopy::{AsBytes, FromBytes, Unaligned, I64}; use heed::EnvOpenOptions; use serde::{Deserialize, Serialize}; @@ -65,14 +65,13 @@ fn main() -> Result<(), Box> { wtxn.commit()?; - // it is prefered to use zerocopy when possible - #[derive(Debug, PartialEq, Eq, AsBytes, FromBytes, Unaligned)] + #[derive(Debug, PartialEq, Eq, Clone, Copy, Pod, Zeroable)] #[repr(C)] struct ZeroBytes { bytes: [u8; 12], } - let db = env.create_poly_database(Some("zerocopy-struct"))?; + let db = env.create_poly_database(Some("nocopy-struct"))?; let mut wtxn = env.write_txn()?; diff --git a/heed/examples/all-types.rs b/heed/examples/all-types.rs index 55361f23..0bc2b08f 100644 --- a/heed/examples/all-types.rs +++ b/heed/examples/all-types.rs @@ -2,9 +2,9 @@ use std::error::Error; use std::fs; use std::path::Path; +use heed::bytemuck::{Pod, Zeroable}; use heed::byteorder::BE; use heed::types::*; -use heed::bytemuck::{Pod, Zeroable}; use heed::{Database, EnvOpenOptions}; use serde::{Deserialize, Serialize}; @@ -71,23 +71,14 @@ fn main() -> Result<(), Box> { wtxn.commit()?; - // it is prefered to use zerocopy when possible - #[derive(Debug, Clone, Copy, PartialEq, Eq)] + // it is prefered to use bytemuck when possible + #[derive(Debug, Clone, Copy, PartialEq, Eq, Zeroable, Pod)] #[repr(C)] struct ZeroBytes { bytes: [u8; 12], } - unsafe impl Zeroable for ZeroBytes { - fn zeroed() -> Self { - ZeroBytes { bytes: Default::default() } - } - } - - unsafe impl Pod for ZeroBytes { } - - let db: Database> = - env.create_database(Some("zerocopy-struct"))?; + let db: Database> = env.create_database(Some("simple-struct"))?; let mut wtxn = env.write_txn()?; diff --git a/heed/src/db/polymorph.rs b/heed/src/db/polymorph.rs index da434c88..677346d9 100644 --- a/heed/src/db/polymorph.rs +++ b/heed/src/db/polymorph.rs @@ -21,7 +21,7 @@ use crate::*; /// # use heed::EnvOpenOptions; /// use heed::PolyDatabase; /// use heed::types::*; -/// use heed::{zerocopy::I64, byteorder::BigEndian}; +/// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -64,7 +64,7 @@ use crate::*; /// # use heed::EnvOpenOptions; /// use heed::PolyDatabase; /// use heed::types::*; -/// use heed::{zerocopy::I64, byteorder::BigEndian}; +/// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -190,7 +190,7 @@ impl PolyDatabase { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; - /// use heed::{zerocopy::U32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -258,7 +258,7 @@ impl PolyDatabase { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; - /// use heed::{zerocopy::U32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -330,7 +330,7 @@ impl PolyDatabase { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; - /// use heed::{zerocopy::U32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -401,7 +401,7 @@ impl PolyDatabase { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; - /// use heed::{zerocopy::U32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -466,7 +466,7 @@ impl PolyDatabase { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; - /// use heed::{zerocopy::I32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -522,7 +522,7 @@ impl PolyDatabase { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; - /// use heed::{zerocopy::I32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -574,7 +574,7 @@ impl PolyDatabase { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; - /// use heed::{zerocopy::I32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -630,7 +630,7 @@ impl PolyDatabase { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; - /// use heed::{zerocopy::I32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -678,7 +678,7 @@ impl PolyDatabase { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; - /// use heed::{zerocopy::I32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -720,7 +720,7 @@ impl PolyDatabase { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; - /// use heed::{zerocopy::I32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -778,7 +778,7 @@ impl PolyDatabase { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; - /// use heed::{zerocopy::I32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -824,7 +824,7 @@ impl PolyDatabase { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; - /// use heed::{zerocopy::I32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -884,7 +884,7 @@ impl PolyDatabase { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; - /// use heed::{zerocopy::I32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -962,7 +962,7 @@ impl PolyDatabase { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; - /// use heed::{zerocopy::I32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -1053,7 +1053,7 @@ impl PolyDatabase { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; - /// use heed::{zerocopy::I32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -1131,7 +1131,7 @@ impl PolyDatabase { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; - /// use heed::{zerocopy::I32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -1222,7 +1222,7 @@ impl PolyDatabase { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; - /// use heed::{zerocopy::I32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -1278,7 +1278,7 @@ impl PolyDatabase { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; - /// use heed::{zerocopy::I32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -1347,7 +1347,7 @@ impl PolyDatabase { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; - /// use heed::{zerocopy::I32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -1403,7 +1403,7 @@ impl PolyDatabase { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; - /// use heed::{zerocopy::I32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -1469,7 +1469,7 @@ impl PolyDatabase { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; - /// use heed::{zerocopy::I32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -1531,7 +1531,7 @@ impl PolyDatabase { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; - /// use heed::{zerocopy::I32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -1592,7 +1592,7 @@ impl PolyDatabase { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; - /// use heed::{zerocopy::I32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -1658,7 +1658,7 @@ impl PolyDatabase { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; - /// use heed::{zerocopy::I32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -1728,7 +1728,7 @@ impl PolyDatabase { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; - /// use heed::{zerocopy::I32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -1777,7 +1777,7 @@ impl PolyDatabase { /// # use heed::EnvOpenOptions; /// use heed::{Database, PolyDatabase}; /// use heed::types::*; - /// use heed::{zerocopy::I32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; diff --git a/heed/src/db/uniform.rs b/heed/src/db/uniform.rs index 0c175425..8d871d5b 100644 --- a/heed/src/db/uniform.rs +++ b/heed/src/db/uniform.rs @@ -1543,7 +1543,7 @@ impl Database { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; - /// use heed::{zerocopy::I32, byteorder::BigEndian}; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; diff --git a/heed/src/env.rs b/heed/src/env.rs index cf658271..4dcf2d8a 100644 --- a/heed/src/env.rs +++ b/heed/src/env.rs @@ -102,7 +102,7 @@ impl EnvOpenOptions { self } - /// Set one or more LMDB flags (see ). + /// Set one or [more LMDB flags](http://www.lmdb.tech/doc/group__mdb__env.html). /// ``` /// use std::fs; /// use std::path::Path; @@ -111,7 +111,7 @@ impl EnvOpenOptions { /// use heed::flags::Flags; /// /// # fn main() -> Result<(), Box> { - /// fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?; + /// fs::create_dir_all(Path::new("target").join("database.mdb"))?; /// let mut env_builder = EnvOpenOptions::new(); /// unsafe { /// env_builder.flag(Flags::MdbNoTls); diff --git a/heed/src/iter/mod.rs b/heed/src/iter/mod.rs index d590186d..453a04fc 100644 --- a/heed/src/iter/mod.rs +++ b/heed/src/iter/mod.rs @@ -65,7 +65,6 @@ mod tests { fn iter_last() { use crate::byteorder::BigEndian; use crate::types::*; - use crate::zerocopy::I32; use crate::EnvOpenOptions; let dir = tempfile::tempdir().unwrap(); @@ -130,7 +129,6 @@ mod tests { fn range_iter_last() { use crate::byteorder::BigEndian; use crate::types::*; - use crate::zerocopy::I32; use crate::EnvOpenOptions; let dir = tempfile::tempdir().unwrap(); @@ -363,7 +361,6 @@ mod tests { fn rev_range_iter_last() { use crate::byteorder::BigEndian; use crate::types::*; - use crate::zerocopy::I32; use crate::EnvOpenOptions; let dir = tempfile::tempdir().unwrap(); diff --git a/heed/src/lib.rs b/heed/src/lib.rs index 394156cd..514374ae 100644 --- a/heed/src/lib.rs +++ b/heed/src/lib.rs @@ -1,11 +1,11 @@ //! Crate `heed` is a high-level wrapper of [LMDB], high-level doesn't mean heavy (think about Rust). //! //! It provides you a way to store types in LMDB without any limit and with a minimal overhead as possible, -//! relying on the [zerocopy] library to avoid copying bytes when that's unnecessary and the serde library +//! relying on the [bytemuck] library to avoid copying bytes when that's unnecessary and the serde library //! when this is unavoidable. //! //! The Lightning Memory-Mapped Database (LMDB) directly maps files parts into main memory, combined -//! with the zerocopy library allows us to safely zero-copy parse and serialize Rust types into LMDB. +//! with the bytemuck library allows us to safely zero-copy parse and serialize Rust types into LMDB. //! //! [LMDB]: https://en.wikipedia.org/wiki/Lightning_Memory-Mapped_Database //! @@ -58,7 +58,7 @@ mod txn; use std::{error, fmt, io, result}; use heed_traits as traits; -pub use {byteorder, heed_types as types, zerocopy}; +pub use {bytemuck, byteorder, heed_types as types}; use self::cursor::{RoCursor, RwCursor}; pub use self::db::{Database, PolyDatabase}; From 4f488b055e0b709fd2dfc62c559a722456e2edce Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Wed, 6 Jul 2022 17:21:02 +0200 Subject: [PATCH 07/57] Remove the Generic T type from the transactions --- heed/examples/all-types-poly.rs | 42 ++-- heed/src/cursor.rs | 4 +- heed/src/db/polymorph.rs | 404 +++++++++++++++----------------- heed/src/db/uniform.rs | 145 +++++------- heed/src/env.rs | 13 +- heed/src/txn.rs | 40 ++-- 6 files changed, 295 insertions(+), 353 deletions(-) diff --git a/heed/examples/all-types-poly.rs b/heed/examples/all-types-poly.rs index edba1168..dfa2b788 100644 --- a/heed/examples/all-types-poly.rs +++ b/heed/examples/all-types-poly.rs @@ -25,8 +25,8 @@ fn main() -> Result<(), Box> { let db = env.create_poly_database(Some("kikou"))?; let mut wtxn = env.write_txn()?; - db.put::<_, OwnedType<[i32; 2]>, Str>(&mut wtxn, &[2, 3], "what's up?")?; - let ret = db.get::<_, OwnedType<[i32; 2]>, Str>(&wtxn, &[2, 3])?; + db.put::, Str>(&mut wtxn, &[2, 3], "what's up?")?; + let ret = db.get::, Str>(&wtxn, &[2, 3])?; println!("{:?}", ret); wtxn.commit()?; @@ -35,8 +35,8 @@ fn main() -> Result<(), Box> { let db = env.create_poly_database(Some("kiki"))?; let mut wtxn = env.write_txn()?; - db.put::<_, Str, ByteSlice>(&mut wtxn, "hello", &[2, 3][..])?; - let ret = db.get::<_, Str, ByteSlice>(&wtxn, "hello")?; + db.put::(&mut wtxn, "hello", &[2, 3][..])?; + let ret = db.get::(&wtxn, "hello")?; println!("{:?}", ret); wtxn.commit()?; @@ -52,15 +52,15 @@ fn main() -> Result<(), Box> { let mut wtxn = env.write_txn()?; let hello = Hello { string: "hi" }; - db.put::<_, Str, SerdeBincode>(&mut wtxn, "hello", &hello)?; + db.put::>(&mut wtxn, "hello", &hello)?; - let ret = db.get::<_, Str, SerdeBincode>(&wtxn, "hello")?; + let ret = db.get::>(&wtxn, "hello")?; println!("serde-bincode:\t{:?}", ret); let hello = Hello { string: "hi" }; - db.put::<_, Str, SerdeJson>(&mut wtxn, "hello", &hello)?; + db.put::>(&mut wtxn, "hello", &hello)?; - let ret = db.get::<_, Str, SerdeJson>(&wtxn, "hello")?; + let ret = db.get::>(&wtxn, "hello")?; println!("serde-json:\t{:?}", ret); wtxn.commit()?; @@ -76,9 +76,9 @@ fn main() -> Result<(), Box> { let mut wtxn = env.write_txn()?; let zerobytes = ZeroBytes { bytes: [24; 12] }; - db.put::<_, Str, UnalignedType>(&mut wtxn, "zero", &zerobytes)?; + db.put::>(&mut wtxn, "zero", &zerobytes)?; - let ret = db.get::<_, Str, UnalignedType>(&wtxn, "zero")?; + let ret = db.get::>(&wtxn, "zero")?; println!("{:?}", ret); wtxn.commit()?; @@ -87,12 +87,12 @@ fn main() -> Result<(), Box> { let db = env.create_poly_database(Some("ignored-data"))?; let mut wtxn = env.write_txn()?; - db.put::<_, Str, Unit>(&mut wtxn, "hello", &())?; - let ret = db.get::<_, Str, Unit>(&wtxn, "hello")?; + db.put::(&mut wtxn, "hello", &())?; + let ret = db.get::(&wtxn, "hello")?; println!("{:?}", ret); - let ret = db.get::<_, Str, Unit>(&wtxn, "non-existant")?; + let ret = db.get::(&wtxn, "non-existant")?; println!("{:?}", ret); wtxn.commit()?; @@ -117,27 +117,27 @@ fn main() -> Result<(), Box> { let db = env.create_poly_database(Some("big-endian-iter"))?; let mut wtxn = env.write_txn()?; - db.put::<_, OwnedType, Unit>(&mut wtxn, &BEI64::new(0), &())?; - db.put::<_, OwnedType, Unit>(&mut wtxn, &BEI64::new(68), &())?; - db.put::<_, OwnedType, Unit>(&mut wtxn, &BEI64::new(35), &())?; - db.put::<_, OwnedType, Unit>(&mut wtxn, &BEI64::new(42), &())?; + db.put::, Unit>(&mut wtxn, &BEI64::new(0), &())?; + db.put::, Unit>(&mut wtxn, &BEI64::new(68), &())?; + db.put::, Unit>(&mut wtxn, &BEI64::new(35), &())?; + db.put::, Unit>(&mut wtxn, &BEI64::new(42), &())?; - let rets: Result, _> = db.iter::<_, OwnedType, Unit>(&wtxn)?.collect(); + let rets: Result, _> = db.iter::, Unit>(&wtxn)?.collect(); println!("{:?}", rets); // or iterate over ranges too!!! let range = BEI64::new(35)..=BEI64::new(42); let rets: Result, _> = - db.range::<_, OwnedType, Unit, _>(&wtxn, &range)?.collect(); + db.range::, Unit, _>(&wtxn, &range)?.collect(); println!("{:?}", rets); // delete a range of key let range = BEI64::new(35)..=BEI64::new(42); - let deleted: usize = db.delete_range::<_, OwnedType, _>(&mut wtxn, &range)?; + let deleted: usize = db.delete_range::, _>(&mut wtxn, &range)?; - let rets: Result, _> = db.iter::<_, OwnedType, Unit>(&wtxn)?.collect(); + let rets: Result, _> = db.iter::, Unit>(&wtxn)?.collect(); println!("deleted: {:?}, {:?}", deleted, rets); wtxn.commit()?; diff --git a/heed/src/cursor.rs b/heed/src/cursor.rs index 787f982d..476959f9 100644 --- a/heed/src/cursor.rs +++ b/heed/src/cursor.rs @@ -11,7 +11,7 @@ pub struct RoCursor<'txn> { } impl<'txn> RoCursor<'txn> { - pub(crate) fn new(txn: &'txn RoTxn, dbi: ffi::MDB_dbi) -> Result> { + pub(crate) fn new(txn: &'txn RoTxn, dbi: ffi::MDB_dbi) -> Result> { let mut cursor: *mut ffi::MDB_cursor = ptr::null_mut(); unsafe { mdb_result(ffi::mdb_cursor_open(txn.txn, dbi, &mut cursor))? } @@ -184,7 +184,7 @@ pub struct RwCursor<'txn> { } impl<'txn> RwCursor<'txn> { - pub(crate) fn new(txn: &'txn RwTxn, dbi: ffi::MDB_dbi) -> Result> { + pub(crate) fn new(txn: &'txn RwTxn, dbi: ffi::MDB_dbi) -> Result> { Ok(RwCursor { cursor: RoCursor::new(txn, dbi)? }) } diff --git a/heed/src/db/polymorph.rs b/heed/src/db/polymorph.rs index 677346d9..26b1a54e 100644 --- a/heed/src/db/polymorph.rs +++ b/heed/src/db/polymorph.rs @@ -35,14 +35,14 @@ use crate::*; /// /// let mut wtxn = env.write_txn()?; /// # db.clear(&mut wtxn)?; -/// db.put::<_, OwnedType, Unit>(&mut wtxn, &BEI64::new(0), &())?; -/// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI64::new(35), "thirty five")?; -/// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI64::new(42), "forty two")?; -/// db.put::<_, OwnedType, Unit>(&mut wtxn, &BEI64::new(68), &())?; +/// db.put::, Unit>(&mut wtxn, &BEI64::new(0), &())?; +/// db.put::, Str>(&mut wtxn, &BEI64::new(35), "thirty five")?; +/// db.put::, Str>(&mut wtxn, &BEI64::new(42), "forty two")?; +/// db.put::, Unit>(&mut wtxn, &BEI64::new(68), &())?; /// /// // you can iterate over database entries in order /// let range = BEI64::new(35)..=BEI64::new(42); -/// let mut range = db.range::<_, OwnedType, Str, _>(&wtxn, &range)?; +/// let mut range = db.range::, Str, _>(&wtxn, &range)?; /// assert_eq!(range.next().transpose()?, Some((BEI64::new(35), "thirty five"))); /// assert_eq!(range.next().transpose()?, Some((BEI64::new(42), "forty two"))); /// assert_eq!(range.next().transpose()?, None); @@ -78,17 +78,17 @@ use crate::*; /// /// let mut wtxn = env.write_txn()?; /// # db.clear(&mut wtxn)?; -/// db.put::<_, OwnedType, Unit>(&mut wtxn, &BEI64::new(0), &())?; -/// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI64::new(35), "thirty five")?; -/// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI64::new(42), "forty two")?; -/// db.put::<_, OwnedType, Unit>(&mut wtxn, &BEI64::new(68), &())?; +/// db.put::, Unit>(&mut wtxn, &BEI64::new(0), &())?; +/// db.put::, Str>(&mut wtxn, &BEI64::new(35), "thirty five")?; +/// db.put::, Str>(&mut wtxn, &BEI64::new(42), "forty two")?; +/// db.put::, Unit>(&mut wtxn, &BEI64::new(68), &())?; /// /// // even delete a range of keys /// let range = BEI64::new(35)..=BEI64::new(42); -/// let deleted = db.delete_range::<_, OwnedType, _>(&mut wtxn, &range)?; +/// let deleted = db.delete_range::, _>(&mut wtxn, &range)?; /// assert_eq!(deleted, 2); /// -/// let rets: Result<_, _> = db.iter::<_, OwnedType, Unit>(&wtxn)?.collect(); +/// let rets: Result<_, _> = db.iter::, Unit>(&wtxn)?.collect(); /// let rets: Vec<(BEI64, _)> = rets?; /// /// let expected = vec![ @@ -134,21 +134,21 @@ impl PolyDatabase { /// /// let mut wtxn = env.write_txn()?; /// # db.clear(&mut wtxn)?; - /// db.put::<_, Str, OwnedType>(&mut wtxn, "i-am-forty-two", &42)?; - /// db.put::<_, Str, OwnedType>(&mut wtxn, "i-am-twenty-seven", &27)?; + /// db.put::>(&mut wtxn, "i-am-forty-two", &42)?; + /// db.put::>(&mut wtxn, "i-am-twenty-seven", &27)?; /// - /// let ret = db.get::<_, Str, OwnedType>(&wtxn, "i-am-forty-two")?; + /// let ret = db.get::>(&wtxn, "i-am-forty-two")?; /// assert_eq!(ret, Some(42)); /// - /// let ret = db.get::<_, Str, OwnedType>(&wtxn, "i-am-twenty-one")?; + /// let ret = db.get::>(&wtxn, "i-am-twenty-one")?; /// assert_eq!(ret, None); /// /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn get<'a, 'txn, T, KC, DC>( + pub fn get<'a, 'txn, KC, DC>( &self, - txn: &'txn RoTxn, + txn: &'txn RoTxn, key: &'a KC::EItem, ) -> Result> where @@ -204,25 +204,25 @@ impl PolyDatabase { /// /// let mut wtxn = env.write_txn()?; /// # db.clear(&mut wtxn)?; - /// db.put::<_, OwnedType, Unit>(&mut wtxn, &BEU32::new(27), &())?; - /// db.put::<_, OwnedType, Unit>(&mut wtxn, &BEU32::new(42), &())?; - /// db.put::<_, OwnedType, Unit>(&mut wtxn, &BEU32::new(43), &())?; + /// db.put::, Unit>(&mut wtxn, &BEU32::new(27), &())?; + /// db.put::, Unit>(&mut wtxn, &BEU32::new(42), &())?; + /// db.put::, Unit>(&mut wtxn, &BEU32::new(43), &())?; /// - /// let ret = db.get_lower_than::<_, OwnedType, Unit>(&wtxn, &BEU32::new(4404))?; + /// let ret = db.get_lower_than::, Unit>(&wtxn, &BEU32::new(4404))?; /// assert_eq!(ret, Some((BEU32::new(43), ()))); /// - /// let ret = db.get_lower_than::<_, OwnedType, Unit>(&wtxn, &BEU32::new(43))?; + /// let ret = db.get_lower_than::, Unit>(&wtxn, &BEU32::new(43))?; /// assert_eq!(ret, Some((BEU32::new(42), ()))); /// - /// let ret = db.get_lower_than::<_, OwnedType, Unit>(&wtxn, &BEU32::new(27))?; + /// let ret = db.get_lower_than::, Unit>(&wtxn, &BEU32::new(27))?; /// assert_eq!(ret, None); /// /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn get_lower_than<'a, 'txn, T, KC, DC>( + pub fn get_lower_than<'a, 'txn, KC, DC>( &self, - txn: &'txn RoTxn, + txn: &'txn RoTxn, key: &'a KC::EItem, ) -> Result> where @@ -272,25 +272,25 @@ impl PolyDatabase { /// /// let mut wtxn = env.write_txn()?; /// # db.clear(&mut wtxn)?; - /// db.put::<_, OwnedType, Unit>(&mut wtxn, &BEU32::new(27), &())?; - /// db.put::<_, OwnedType, Unit>(&mut wtxn, &BEU32::new(42), &())?; - /// db.put::<_, OwnedType, Unit>(&mut wtxn, &BEU32::new(43), &())?; + /// db.put::, Unit>(&mut wtxn, &BEU32::new(27), &())?; + /// db.put::, Unit>(&mut wtxn, &BEU32::new(42), &())?; + /// db.put::, Unit>(&mut wtxn, &BEU32::new(43), &())?; /// - /// let ret = db.get_lower_than_or_equal_to::<_, OwnedType, Unit>(&wtxn, &BEU32::new(4404))?; + /// let ret = db.get_lower_than_or_equal_to::, Unit>(&wtxn, &BEU32::new(4404))?; /// assert_eq!(ret, Some((BEU32::new(43), ()))); /// - /// let ret = db.get_lower_than_or_equal_to::<_, OwnedType, Unit>(&wtxn, &BEU32::new(43))?; + /// let ret = db.get_lower_than_or_equal_to::, Unit>(&wtxn, &BEU32::new(43))?; /// assert_eq!(ret, Some((BEU32::new(43), ()))); /// - /// let ret = db.get_lower_than_or_equal_to::<_, OwnedType, Unit>(&wtxn, &BEU32::new(26))?; + /// let ret = db.get_lower_than_or_equal_to::, Unit>(&wtxn, &BEU32::new(26))?; /// assert_eq!(ret, None); /// /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn get_lower_than_or_equal_to<'a, 'txn, T, KC, DC>( + pub fn get_lower_than_or_equal_to<'a, 'txn, KC, DC>( &self, - txn: &'txn RoTxn, + txn: &'txn RoTxn, key: &'a KC::EItem, ) -> Result> where @@ -344,25 +344,25 @@ impl PolyDatabase { /// /// let mut wtxn = env.write_txn()?; /// # db.clear(&mut wtxn)?; - /// db.put::<_, OwnedType, Unit>(&mut wtxn, &BEU32::new(27), &())?; - /// db.put::<_, OwnedType, Unit>(&mut wtxn, &BEU32::new(42), &())?; - /// db.put::<_, OwnedType, Unit>(&mut wtxn, &BEU32::new(43), &())?; + /// db.put::, Unit>(&mut wtxn, &BEU32::new(27), &())?; + /// db.put::, Unit>(&mut wtxn, &BEU32::new(42), &())?; + /// db.put::, Unit>(&mut wtxn, &BEU32::new(43), &())?; /// - /// let ret = db.get_greater_than::<_, OwnedType, Unit>(&wtxn, &BEU32::new(0))?; + /// let ret = db.get_greater_than::, Unit>(&wtxn, &BEU32::new(0))?; /// assert_eq!(ret, Some((BEU32::new(27), ()))); /// - /// let ret = db.get_greater_than::<_, OwnedType, Unit>(&wtxn, &BEU32::new(42))?; + /// let ret = db.get_greater_than::, Unit>(&wtxn, &BEU32::new(42))?; /// assert_eq!(ret, Some((BEU32::new(43), ()))); /// - /// let ret = db.get_greater_than::<_, OwnedType, Unit>(&wtxn, &BEU32::new(43))?; + /// let ret = db.get_greater_than::, Unit>(&wtxn, &BEU32::new(43))?; /// assert_eq!(ret, None); /// /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn get_greater_than<'a, 'txn, T, KC, DC>( + pub fn get_greater_than<'a, 'txn, KC, DC>( &self, - txn: &'txn RoTxn, + txn: &'txn RoTxn, key: &'a KC::EItem, ) -> Result> where @@ -415,25 +415,25 @@ impl PolyDatabase { /// /// let mut wtxn = env.write_txn()?; /// # db.clear(&mut wtxn)?; - /// db.put::<_, OwnedType, Unit>(&mut wtxn, &BEU32::new(27), &())?; - /// db.put::<_, OwnedType, Unit>(&mut wtxn, &BEU32::new(42), &())?; - /// db.put::<_, OwnedType, Unit>(&mut wtxn, &BEU32::new(43), &())?; + /// db.put::, Unit>(&mut wtxn, &BEU32::new(27), &())?; + /// db.put::, Unit>(&mut wtxn, &BEU32::new(42), &())?; + /// db.put::, Unit>(&mut wtxn, &BEU32::new(43), &())?; /// - /// let ret = db.get_greater_than_or_equal_to::<_, OwnedType, Unit>(&wtxn, &BEU32::new(0))?; + /// let ret = db.get_greater_than_or_equal_to::, Unit>(&wtxn, &BEU32::new(0))?; /// assert_eq!(ret, Some((BEU32::new(27), ()))); /// - /// let ret = db.get_greater_than_or_equal_to::<_, OwnedType, Unit>(&wtxn, &BEU32::new(42))?; + /// let ret = db.get_greater_than_or_equal_to::, Unit>(&wtxn, &BEU32::new(42))?; /// assert_eq!(ret, Some((BEU32::new(42), ()))); /// - /// let ret = db.get_greater_than_or_equal_to::<_, OwnedType, Unit>(&wtxn, &BEU32::new(44))?; + /// let ret = db.get_greater_than_or_equal_to::, Unit>(&wtxn, &BEU32::new(44))?; /// assert_eq!(ret, None); /// /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn get_greater_than_or_equal_to<'a, 'txn, T, KC, DC>( + pub fn get_greater_than_or_equal_to<'a, 'txn, KC, DC>( &self, - txn: &'txn RoTxn, + txn: &'txn RoTxn, key: &'a KC::EItem, ) -> Result> where @@ -480,19 +480,16 @@ impl PolyDatabase { /// /// let mut wtxn = env.write_txn()?; /// # db.clear(&mut wtxn)?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; /// - /// let ret = db.first::<_, OwnedType, Str>(&wtxn)?; + /// let ret = db.first::, Str>(&wtxn)?; /// assert_eq!(ret, Some((BEI32::new(27), "i-am-twenty-seven"))); /// /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn first<'txn, T, KC, DC>( - &self, - txn: &'txn RoTxn, - ) -> Result> + pub fn first<'txn, KC, DC>(&self, txn: &'txn RoTxn) -> Result> where KC: BytesDecode<'txn>, DC: BytesDecode<'txn>, @@ -536,19 +533,16 @@ impl PolyDatabase { /// /// let mut wtxn = env.write_txn()?; /// # db.clear(&mut wtxn)?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; /// - /// let ret = db.last::<_, OwnedType, Str>(&wtxn)?; + /// let ret = db.last::, Str>(&wtxn)?; /// assert_eq!(ret, Some((BEI32::new(42), "i-am-forty-two"))); /// /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn last<'txn, T, KC, DC>( - &self, - txn: &'txn RoTxn, - ) -> Result> + pub fn last<'txn, KC, DC>(&self, txn: &'txn RoTxn) -> Result> where KC: BytesDecode<'txn>, DC: BytesDecode<'txn>, @@ -588,15 +582,15 @@ impl PolyDatabase { /// /// let mut wtxn = env.write_txn()?; /// # db.clear(&mut wtxn)?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(521), "i-am-five-hundred-and-twenty-one")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(521), "i-am-five-hundred-and-twenty-one")?; /// /// let ret = db.len(&wtxn)?; /// assert_eq!(ret, 4); /// - /// db.delete::<_, OwnedType>(&mut wtxn, &BEI32::new(27))?; + /// db.delete::>(&mut wtxn, &BEI32::new(27))?; /// /// let ret = db.len(&wtxn)?; /// assert_eq!(ret, 3); @@ -604,7 +598,7 @@ impl PolyDatabase { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn len<'txn, T>(&self, txn: &'txn RoTxn) -> Result { + pub fn len<'txn>(&self, txn: &'txn RoTxn) -> Result { assert_eq!(self.env_ident, txn.env.env_mut_ptr() as usize); let mut cursor = RoCursor::new(txn, self.dbi)?; @@ -644,10 +638,10 @@ impl PolyDatabase { /// /// let mut wtxn = env.write_txn()?; /// # db.clear(&mut wtxn)?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(521), "i-am-five-hundred-and-twenty-one")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(521), "i-am-five-hundred-and-twenty-one")?; /// /// let ret = db.is_empty(&wtxn)?; /// assert_eq!(ret, false); @@ -660,7 +654,7 @@ impl PolyDatabase { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn is_empty<'txn, T>(&self, txn: &'txn RoTxn) -> Result { + pub fn is_empty<'txn>(&self, txn: &'txn RoTxn) -> Result { assert_eq!(self.env_ident, txn.env.env_mut_ptr() as usize); let mut cursor = RoCursor::new(txn, self.dbi)?; @@ -692,11 +686,11 @@ impl PolyDatabase { /// /// let mut wtxn = env.write_txn()?; /// # db.clear(&mut wtxn)?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; /// - /// let mut iter = db.iter::<_, OwnedType, Str>(&wtxn)?; + /// let mut iter = db.iter::, Str>(&wtxn)?; /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(13), "i-am-thirteen"))); /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(27), "i-am-twenty-seven"))); /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(42), "i-am-forty-two"))); @@ -706,7 +700,7 @@ impl PolyDatabase { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn iter<'txn, T, KC, DC>(&self, txn: &'txn RoTxn) -> Result> { + pub fn iter<'txn, KC, DC>(&self, txn: &'txn RoTxn) -> Result> { assert_eq!(self.env_ident, txn.env.env_mut_ptr() as usize); RoCursor::new(txn, self.dbi).map(|cursor| RoIter::new(cursor)) @@ -734,11 +728,11 @@ impl PolyDatabase { /// /// let mut wtxn = env.write_txn()?; /// # db.clear(&mut wtxn)?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; /// - /// let mut iter = db.iter_mut::<_, OwnedType, Str>(&mut wtxn)?; + /// let mut iter = db.iter_mut::, Str>(&mut wtxn)?; /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(13), "i-am-thirteen"))); /// let ret = unsafe { iter.del_current()? }; /// assert!(ret); @@ -752,19 +746,16 @@ impl PolyDatabase { /// /// drop(iter); /// - /// let ret = db.get::<_, OwnedType, Str>(&wtxn, &BEI32::new(13))?; + /// let ret = db.get::, Str>(&wtxn, &BEI32::new(13))?; /// assert_eq!(ret, None); /// - /// let ret = db.get::<_, OwnedType, Str>(&wtxn, &BEI32::new(42))?; + /// let ret = db.get::, Str>(&wtxn, &BEI32::new(42))?; /// assert_eq!(ret, Some("i-am-the-new-forty-two")); /// /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn iter_mut<'txn, T, KC, DC>( - &self, - txn: &'txn mut RwTxn, - ) -> Result> { + pub fn iter_mut<'txn, KC, DC>(&self, txn: &'txn mut RwTxn) -> Result> { assert_eq!(self.env_ident, txn.txn.env.env_mut_ptr() as usize); RwCursor::new(txn, self.dbi).map(|cursor| RwIter::new(cursor)) @@ -792,11 +783,11 @@ impl PolyDatabase { /// /// let mut wtxn = env.write_txn()?; /// # db.clear(&mut wtxn)?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; /// - /// let mut iter = db.rev_iter::<_, OwnedType, Str>(&wtxn)?; + /// let mut iter = db.rev_iter::, Str>(&wtxn)?; /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(42), "i-am-forty-two"))); /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(27), "i-am-twenty-seven"))); /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(13), "i-am-thirteen"))); @@ -806,10 +797,7 @@ impl PolyDatabase { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn rev_iter<'txn, T, KC, DC>( - &self, - txn: &'txn RoTxn, - ) -> Result> { + pub fn rev_iter<'txn, KC, DC>(&self, txn: &'txn RoTxn) -> Result> { assert_eq!(self.env_ident, txn.env.env_mut_ptr() as usize); RoCursor::new(txn, self.dbi).map(|cursor| RoRevIter::new(cursor)) @@ -838,11 +826,11 @@ impl PolyDatabase { /// /// let mut wtxn = env.write_txn()?; /// # db.clear(&mut wtxn)?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; /// - /// let mut iter = db.rev_iter_mut::<_, OwnedType, Str>(&mut wtxn)?; + /// let mut iter = db.rev_iter_mut::, Str>(&mut wtxn)?; /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(42), "i-am-forty-two"))); /// let ret = unsafe { iter.del_current()? }; /// assert!(ret); @@ -856,18 +844,18 @@ impl PolyDatabase { /// /// drop(iter); /// - /// let ret = db.get::<_, OwnedType, Str>(&wtxn, &BEI32::new(42))?; + /// let ret = db.get::, Str>(&wtxn, &BEI32::new(42))?; /// assert_eq!(ret, None); /// - /// let ret = db.get::<_, OwnedType, Str>(&wtxn, &BEI32::new(13))?; + /// let ret = db.get::, Str>(&wtxn, &BEI32::new(13))?; /// assert_eq!(ret, Some("i-am-the-new-thirteen")); /// /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn rev_iter_mut<'txn, T, KC, DC>( + pub fn rev_iter_mut<'txn, KC, DC>( &self, - txn: &'txn mut RwTxn, + txn: &'txn mut RwTxn, ) -> Result> { assert_eq!(self.env_ident, txn.env.env_mut_ptr() as usize); @@ -898,13 +886,13 @@ impl PolyDatabase { /// /// let mut wtxn = env.write_txn()?; /// # db.clear(&mut wtxn)?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(521), "i-am-five-hundred-and-twenty-one")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(521), "i-am-five-hundred-and-twenty-one")?; /// /// let range = BEI32::new(27)..=BEI32::new(42); - /// let mut iter = db.range::<_, OwnedType, Str, _>(&wtxn, &range)?; + /// let mut iter = db.range::, Str, _>(&wtxn, &range)?; /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(27), "i-am-twenty-seven"))); /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(42), "i-am-forty-two"))); /// assert_eq!(iter.next().transpose()?, None); @@ -913,9 +901,9 @@ impl PolyDatabase { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn range<'a, 'txn, T, KC, DC, R>( + pub fn range<'a, 'txn, KC, DC, R>( &self, - txn: &'txn RoTxn, + txn: &'txn RoTxn, range: &'a R, ) -> Result> where @@ -976,13 +964,13 @@ impl PolyDatabase { /// /// let mut wtxn = env.write_txn()?; /// # db.clear(&mut wtxn)?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(521), "i-am-five-hundred-and-twenty-one")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(521), "i-am-five-hundred-and-twenty-one")?; /// /// let range = BEI32::new(27)..=BEI32::new(42); - /// let mut range = db.range_mut::<_, OwnedType, Str, _>(&mut wtxn, &range)?; + /// let mut range = db.range_mut::, Str, _>(&mut wtxn, &range)?; /// assert_eq!(range.next().transpose()?, Some((BEI32::new(27), "i-am-twenty-seven"))); /// let ret = unsafe { range.del_current()? }; /// assert!(ret); @@ -994,7 +982,7 @@ impl PolyDatabase { /// drop(range); /// /// - /// let mut iter = db.iter::<_, OwnedType, Str>(&wtxn)?; + /// let mut iter = db.iter::, Str>(&wtxn)?; /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(13), "i-am-thirteen"))); /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(42), "i-am-the-new-forty-two"))); /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(521), "i-am-five-hundred-and-twenty-one"))); @@ -1004,9 +992,9 @@ impl PolyDatabase { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn range_mut<'a, 'txn, T, KC, DC, R>( + pub fn range_mut<'a, 'txn, KC, DC, R>( &self, - txn: &'txn mut RwTxn, + txn: &'txn mut RwTxn, range: &'a R, ) -> Result> where @@ -1067,13 +1055,13 @@ impl PolyDatabase { /// /// let mut wtxn = env.write_txn()?; /// # db.clear(&mut wtxn)?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(521), "i-am-five-hundred-and-twenty-one")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(521), "i-am-five-hundred-and-twenty-one")?; /// /// let range = BEI32::new(27)..=BEI32::new(43); - /// let mut iter = db.rev_range::<_, OwnedType, Str, _>(&wtxn, &range)?; + /// let mut iter = db.rev_range::, Str, _>(&wtxn, &range)?; /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(42), "i-am-forty-two"))); /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(27), "i-am-twenty-seven"))); /// assert_eq!(iter.next().transpose()?, None); @@ -1082,9 +1070,9 @@ impl PolyDatabase { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn rev_range<'a, 'txn, T, KC, DC, R>( + pub fn rev_range<'a, 'txn, KC, DC, R>( &self, - txn: &'txn RoTxn, + txn: &'txn RoTxn, range: &'a R, ) -> Result> where @@ -1145,13 +1133,13 @@ impl PolyDatabase { /// /// let mut wtxn = env.write_txn()?; /// # db.clear(&mut wtxn)?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(521), "i-am-five-hundred-and-twenty-one")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(521), "i-am-five-hundred-and-twenty-one")?; /// /// let range = BEI32::new(27)..=BEI32::new(42); - /// let mut range = db.rev_range_mut::<_, OwnedType, Str, _>(&mut wtxn, &range)?; + /// let mut range = db.rev_range_mut::, Str, _>(&mut wtxn, &range)?; /// assert_eq!(range.next().transpose()?, Some((BEI32::new(42), "i-am-forty-two"))); /// let ret = unsafe { range.del_current()? }; /// assert!(ret); @@ -1163,7 +1151,7 @@ impl PolyDatabase { /// drop(range); /// /// - /// let mut iter = db.iter::<_, OwnedType, Str>(&wtxn)?; + /// let mut iter = db.iter::, Str>(&wtxn)?; /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(13), "i-am-thirteen"))); /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(27), "i-am-the-new-twenty-seven"))); /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(521), "i-am-five-hundred-and-twenty-one"))); @@ -1173,9 +1161,9 @@ impl PolyDatabase { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn rev_range_mut<'a, 'txn, T, KC, DC, R>( + pub fn rev_range_mut<'a, 'txn, KC, DC, R>( &self, - txn: &'txn mut RwTxn, + txn: &'txn mut RwTxn, range: &'a R, ) -> Result> where @@ -1236,13 +1224,13 @@ impl PolyDatabase { /// /// let mut wtxn = env.write_txn()?; /// # db.clear(&mut wtxn)?; - /// db.put::<_, Str, OwnedType>(&mut wtxn, "i-am-twenty-eight", &BEI32::new(28))?; - /// db.put::<_, Str, OwnedType>(&mut wtxn, "i-am-twenty-seven", &BEI32::new(27))?; - /// db.put::<_, Str, OwnedType>(&mut wtxn, "i-am-twenty-nine", &BEI32::new(29))?; - /// db.put::<_, Str, OwnedType>(&mut wtxn, "i-am-forty-one", &BEI32::new(41))?; - /// db.put::<_, Str, OwnedType>(&mut wtxn, "i-am-forty-two", &BEI32::new(42))?; + /// db.put::>(&mut wtxn, "i-am-twenty-eight", &BEI32::new(28))?; + /// db.put::>(&mut wtxn, "i-am-twenty-seven", &BEI32::new(27))?; + /// db.put::>(&mut wtxn, "i-am-twenty-nine", &BEI32::new(29))?; + /// db.put::>(&mut wtxn, "i-am-forty-one", &BEI32::new(41))?; + /// db.put::>(&mut wtxn, "i-am-forty-two", &BEI32::new(42))?; /// - /// let mut iter = db.prefix_iter::<_, Str, OwnedType>(&mut wtxn, "i-am-twenty")?; + /// let mut iter = db.prefix_iter::>(&mut wtxn, "i-am-twenty")?; /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-eight", BEI32::new(28)))); /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-nine", BEI32::new(29)))); /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-seven", BEI32::new(27)))); @@ -1252,9 +1240,9 @@ impl PolyDatabase { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn prefix_iter<'a, 'txn, T, KC, DC>( + pub fn prefix_iter<'a, 'txn, KC, DC>( &self, - txn: &'txn RoTxn, + txn: &'txn RoTxn, prefix: &'a KC::EItem, ) -> Result> where @@ -1292,13 +1280,13 @@ impl PolyDatabase { /// /// let mut wtxn = env.write_txn()?; /// # db.clear(&mut wtxn)?; - /// db.put::<_, Str, OwnedType>(&mut wtxn, "i-am-twenty-eight", &BEI32::new(28))?; - /// db.put::<_, Str, OwnedType>(&mut wtxn, "i-am-twenty-seven", &BEI32::new(27))?; - /// db.put::<_, Str, OwnedType>(&mut wtxn, "i-am-twenty-nine", &BEI32::new(29))?; - /// db.put::<_, Str, OwnedType>(&mut wtxn, "i-am-forty-one", &BEI32::new(41))?; - /// db.put::<_, Str, OwnedType>(&mut wtxn, "i-am-forty-two", &BEI32::new(42))?; + /// db.put::>(&mut wtxn, "i-am-twenty-eight", &BEI32::new(28))?; + /// db.put::>(&mut wtxn, "i-am-twenty-seven", &BEI32::new(27))?; + /// db.put::>(&mut wtxn, "i-am-twenty-nine", &BEI32::new(29))?; + /// db.put::>(&mut wtxn, "i-am-forty-one", &BEI32::new(41))?; + /// db.put::>(&mut wtxn, "i-am-forty-two", &BEI32::new(42))?; /// - /// let mut iter = db.prefix_iter_mut::<_, Str, OwnedType>(&mut wtxn, "i-am-twenty")?; + /// let mut iter = db.prefix_iter_mut::>(&mut wtxn, "i-am-twenty")?; /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-eight", BEI32::new(28)))); /// let ret = unsafe { iter.del_current()? }; /// assert!(ret); @@ -1312,18 +1300,18 @@ impl PolyDatabase { /// /// drop(iter); /// - /// let ret = db.get::<_, Str, OwnedType>(&wtxn, "i-am-twenty-eight")?; + /// let ret = db.get::>(&wtxn, "i-am-twenty-eight")?; /// assert_eq!(ret, None); /// - /// let ret = db.get::<_, Str, OwnedType>(&wtxn, "i-am-twenty-seven")?; + /// let ret = db.get::>(&wtxn, "i-am-twenty-seven")?; /// assert_eq!(ret, Some(BEI32::new(27000))); /// /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn prefix_iter_mut<'a, 'txn, T, KC, DC>( + pub fn prefix_iter_mut<'a, 'txn, KC, DC>( &self, - txn: &'txn mut RwTxn, + txn: &'txn mut RwTxn, prefix: &'a KC::EItem, ) -> Result> where @@ -1361,13 +1349,13 @@ impl PolyDatabase { /// /// let mut wtxn = env.write_txn()?; /// # db.clear(&mut wtxn)?; - /// db.put::<_, Str, OwnedType>(&mut wtxn, "i-am-twenty-eight", &BEI32::new(28))?; - /// db.put::<_, Str, OwnedType>(&mut wtxn, "i-am-twenty-seven", &BEI32::new(27))?; - /// db.put::<_, Str, OwnedType>(&mut wtxn, "i-am-twenty-nine", &BEI32::new(29))?; - /// db.put::<_, Str, OwnedType>(&mut wtxn, "i-am-forty-one", &BEI32::new(41))?; - /// db.put::<_, Str, OwnedType>(&mut wtxn, "i-am-forty-two", &BEI32::new(42))?; + /// db.put::>(&mut wtxn, "i-am-twenty-eight", &BEI32::new(28))?; + /// db.put::>(&mut wtxn, "i-am-twenty-seven", &BEI32::new(27))?; + /// db.put::>(&mut wtxn, "i-am-twenty-nine", &BEI32::new(29))?; + /// db.put::>(&mut wtxn, "i-am-forty-one", &BEI32::new(41))?; + /// db.put::>(&mut wtxn, "i-am-forty-two", &BEI32::new(42))?; /// - /// let mut iter = db.rev_prefix_iter::<_, Str, OwnedType>(&mut wtxn, "i-am-twenty")?; + /// let mut iter = db.rev_prefix_iter::>(&mut wtxn, "i-am-twenty")?; /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-seven", BEI32::new(27)))); /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-nine", BEI32::new(29)))); /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-eight", BEI32::new(28)))); @@ -1377,9 +1365,9 @@ impl PolyDatabase { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn rev_prefix_iter<'a, 'txn, T, KC, DC>( + pub fn rev_prefix_iter<'a, 'txn, KC, DC>( &self, - txn: &'txn RoTxn, + txn: &'txn RoTxn, prefix: &'a KC::EItem, ) -> Result> where @@ -1417,13 +1405,13 @@ impl PolyDatabase { /// /// let mut wtxn = env.write_txn()?; /// # db.clear(&mut wtxn)?; - /// db.put::<_, Str, OwnedType>(&mut wtxn, "i-am-twenty-eight", &BEI32::new(28))?; - /// db.put::<_, Str, OwnedType>(&mut wtxn, "i-am-twenty-seven", &BEI32::new(27))?; - /// db.put::<_, Str, OwnedType>(&mut wtxn, "i-am-twenty-nine", &BEI32::new(29))?; - /// db.put::<_, Str, OwnedType>(&mut wtxn, "i-am-forty-one", &BEI32::new(41))?; - /// db.put::<_, Str, OwnedType>(&mut wtxn, "i-am-forty-two", &BEI32::new(42))?; + /// db.put::>(&mut wtxn, "i-am-twenty-eight", &BEI32::new(28))?; + /// db.put::>(&mut wtxn, "i-am-twenty-seven", &BEI32::new(27))?; + /// db.put::>(&mut wtxn, "i-am-twenty-nine", &BEI32::new(29))?; + /// db.put::>(&mut wtxn, "i-am-forty-one", &BEI32::new(41))?; + /// db.put::>(&mut wtxn, "i-am-forty-two", &BEI32::new(42))?; /// - /// let mut iter = db.rev_prefix_iter_mut::<_, Str, OwnedType>(&mut wtxn, "i-am-twenty")?; + /// let mut iter = db.rev_prefix_iter_mut::>(&mut wtxn, "i-am-twenty")?; /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-seven", BEI32::new(27)))); /// let ret = unsafe { iter.del_current()? }; /// assert!(ret); @@ -1437,18 +1425,18 @@ impl PolyDatabase { /// /// drop(iter); /// - /// let ret = db.get::<_, Str, OwnedType>(&wtxn, "i-am-twenty-seven")?; + /// let ret = db.get::>(&wtxn, "i-am-twenty-seven")?; /// assert_eq!(ret, None); /// - /// let ret = db.get::<_, Str, OwnedType>(&wtxn, "i-am-twenty-eight")?; + /// let ret = db.get::>(&wtxn, "i-am-twenty-eight")?; /// assert_eq!(ret, Some(BEI32::new(28000))); /// /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn rev_prefix_iter_mut<'a, 'txn, T, KC, DC>( + pub fn rev_prefix_iter_mut<'a, 'txn, KC, DC>( &self, - txn: &'txn mut RwTxn, + txn: &'txn mut RwTxn, prefix: &'a KC::EItem, ) -> Result> where @@ -1483,20 +1471,20 @@ impl PolyDatabase { /// /// let mut wtxn = env.write_txn()?; /// # db.clear(&mut wtxn)?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(521), "i-am-five-hundred-and-twenty-one")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(521), "i-am-five-hundred-and-twenty-one")?; /// - /// let ret = db.get::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(27))?; + /// let ret = db.get::, Str>(&mut wtxn, &BEI32::new(27))?; /// assert_eq!(ret, Some("i-am-twenty-seven")); /// /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn put<'a, T, KC, DC>( + pub fn put<'a, KC, DC>( &self, - txn: &mut RwTxn, + txn: &mut RwTxn, key: &'a KC::EItem, data: &'a DC::EItem, ) -> Result<()> @@ -1545,20 +1533,20 @@ impl PolyDatabase { /// /// let mut wtxn = env.write_txn()?; /// # db.clear(&mut wtxn)?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(521), "i-am-five-hundred-and-twenty-one")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(521), "i-am-five-hundred-and-twenty-one")?; /// - /// let ret = db.get::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(27))?; + /// let ret = db.get::, Str>(&mut wtxn, &BEI32::new(27))?; /// assert_eq!(ret, Some("i-am-twenty-seven")); /// /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn append<'a, T, KC, DC>( + pub fn append<'a, KC, DC>( &self, - txn: &mut RwTxn, + txn: &mut RwTxn, key: &'a KC::EItem, data: &'a DC::EItem, ) -> Result<()> @@ -1606,24 +1594,24 @@ impl PolyDatabase { /// /// let mut wtxn = env.write_txn()?; /// # db.clear(&mut wtxn)?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(521), "i-am-five-hundred-and-twenty-one")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(521), "i-am-five-hundred-and-twenty-one")?; /// - /// let ret = db.delete::<_, OwnedType>(&mut wtxn, &BEI32::new(27))?; + /// let ret = db.delete::>(&mut wtxn, &BEI32::new(27))?; /// assert_eq!(ret, true); /// - /// let ret = db.get::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(27))?; + /// let ret = db.get::, Str>(&mut wtxn, &BEI32::new(27))?; /// assert_eq!(ret, None); /// - /// let ret = db.delete::<_, OwnedType>(&mut wtxn, &BEI32::new(467))?; + /// let ret = db.delete::>(&mut wtxn, &BEI32::new(467))?; /// assert_eq!(ret, false); /// /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn delete<'a, T, KC>(&self, txn: &mut RwTxn, key: &'a KC::EItem) -> Result + pub fn delete<'a, KC>(&self, txn: &mut RwTxn, key: &'a KC::EItem) -> Result where KC: BytesEncode<'a>, { @@ -1672,16 +1660,16 @@ impl PolyDatabase { /// /// let mut wtxn = env.write_txn()?; /// # db.clear(&mut wtxn)?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(521), "i-am-five-hundred-and-twenty-one")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(521), "i-am-five-hundred-and-twenty-one")?; /// /// let range = BEI32::new(27)..=BEI32::new(42); - /// let ret = db.delete_range::<_, OwnedType, _>(&mut wtxn, &range)?; + /// let ret = db.delete_range::, _>(&mut wtxn, &range)?; /// assert_eq!(ret, 2); /// - /// let mut iter = db.iter::<_, OwnedType, Str>(&wtxn)?; + /// let mut iter = db.iter::, Str>(&wtxn)?; /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(13), "i-am-thirteen"))); /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(521), "i-am-five-hundred-and-twenty-one"))); /// assert_eq!(iter.next().transpose()?, None); @@ -1690,11 +1678,7 @@ impl PolyDatabase { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn delete_range<'a, 'txn, T, KC, R>( - &self, - txn: &'txn mut RwTxn, - range: &'a R, - ) -> Result + pub fn delete_range<'a, 'txn, KC, R>(&self, txn: &'txn mut RwTxn, range: &'a R) -> Result where KC: BytesEncode<'a> + BytesDecode<'txn>, R: RangeBounds, @@ -1702,7 +1686,7 @@ impl PolyDatabase { assert_eq!(self.env_ident, txn.txn.env.env_mut_ptr() as usize); let mut count = 0; - let mut iter = self.range_mut::(txn, range)?; + let mut iter = self.range_mut::(txn, range)?; while iter.next().is_some() { // safety: We do not keep any reference from the database while using `del_current`. @@ -1742,10 +1726,10 @@ impl PolyDatabase { /// /// let mut wtxn = env.write_txn()?; /// # db.clear(&mut wtxn)?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; - /// db.put::<_, OwnedType, Str>(&mut wtxn, &BEI32::new(521), "i-am-five-hundred-and-twenty-one")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; + /// db.put::, Str>(&mut wtxn, &BEI32::new(521), "i-am-five-hundred-and-twenty-one")?; /// /// db.clear(&mut wtxn)?; /// @@ -1755,7 +1739,7 @@ impl PolyDatabase { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn clear(&self, txn: &mut RwTxn) -> Result<()> { + pub fn clear(&self, txn: &mut RwTxn) -> Result<()> { assert_eq!(self.env_ident, txn.txn.env.env_mut_ptr() as usize); unsafe { mdb_result(ffi::mdb_drop(txn.txn.txn, self.dbi, 0)).map_err(Into::into) } diff --git a/heed/src/db/uniform.rs b/heed/src/db/uniform.rs index 8d871d5b..4e661678 100644 --- a/heed/src/db/uniform.rs +++ b/heed/src/db/uniform.rs @@ -157,16 +157,12 @@ impl Database { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn get<'a, 'txn, T>( - &self, - txn: &'txn RoTxn, - key: &'a KC::EItem, - ) -> Result> + pub fn get<'a, 'txn>(&self, txn: &'txn RoTxn, key: &'a KC::EItem) -> Result> where KC: BytesEncode<'a>, DC: BytesDecode<'txn>, { - self.dyndb.get::(txn, key) + self.dyndb.get::(txn, key) } /// Retrieves the key/value pair lower than the given one in this database. @@ -212,16 +208,16 @@ impl Database { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn get_lower_than<'a, 'txn, T>( + pub fn get_lower_than<'a, 'txn>( &self, - txn: &'txn RoTxn, + txn: &'txn RoTxn, key: &'a KC::EItem, ) -> Result> where KC: BytesEncode<'a> + BytesDecode<'txn>, DC: BytesDecode<'txn>, { - self.dyndb.get_lower_than::(txn, key) + self.dyndb.get_lower_than::(txn, key) } /// Retrieves the key/value pair lower than or equal to the given one in this database. @@ -267,16 +263,16 @@ impl Database { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn get_lower_than_or_equal_to<'a, 'txn, T>( + pub fn get_lower_than_or_equal_to<'a, 'txn>( &self, - txn: &'txn RoTxn, + txn: &'txn RoTxn, key: &'a KC::EItem, ) -> Result> where KC: BytesEncode<'a> + BytesDecode<'txn>, DC: BytesDecode<'txn>, { - self.dyndb.get_lower_than_or_equal_to::(txn, key) + self.dyndb.get_lower_than_or_equal_to::(txn, key) } /// Retrieves the key/value pair greater than the given one in this database. @@ -322,16 +318,16 @@ impl Database { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn get_greater_than<'a, 'txn, T>( + pub fn get_greater_than<'a, 'txn>( &self, - txn: &'txn RoTxn, + txn: &'txn RoTxn, key: &'a KC::EItem, ) -> Result> where KC: BytesEncode<'a> + BytesDecode<'txn>, DC: BytesDecode<'txn>, { - self.dyndb.get_greater_than::(txn, key) + self.dyndb.get_greater_than::(txn, key) } /// Retrieves the key/value pair greater than or equal to the given one in this database. @@ -377,16 +373,16 @@ impl Database { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn get_greater_than_or_equal_to<'a, 'txn, T>( + pub fn get_greater_than_or_equal_to<'a, 'txn>( &self, - txn: &'txn RoTxn, + txn: &'txn RoTxn, key: &'a KC::EItem, ) -> Result> where KC: BytesEncode<'a> + BytesDecode<'txn>, DC: BytesDecode<'txn>, { - self.dyndb.get_greater_than_or_equal_to::(txn, key) + self.dyndb.get_greater_than_or_equal_to::(txn, key) } /// Retrieves the first key/value pair of this database. @@ -424,12 +420,12 @@ impl Database { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn first<'txn, T>(&self, txn: &'txn RoTxn) -> Result> + pub fn first<'txn>(&self, txn: &'txn RoTxn) -> Result> where KC: BytesDecode<'txn>, DC: BytesDecode<'txn>, { - self.dyndb.first::(txn) + self.dyndb.first::(txn) } /// Retrieves the last key/value pair of this database. @@ -467,12 +463,12 @@ impl Database { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn last<'txn, T>(&self, txn: &'txn RoTxn) -> Result> + pub fn last<'txn>(&self, txn: &'txn RoTxn) -> Result> where KC: BytesDecode<'txn>, DC: BytesDecode<'txn>, { - self.dyndb.last::(txn) + self.dyndb.last::(txn) } /// Returns the number of elements in this database. @@ -513,7 +509,7 @@ impl Database { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn len<'txn, T>(&self, txn: &'txn RoTxn) -> Result { + pub fn len<'txn>(&self, txn: &'txn RoTxn) -> Result { self.dyndb.len(txn) } @@ -555,7 +551,7 @@ impl Database { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn is_empty<'txn, T>(&self, txn: &'txn RoTxn) -> Result { + pub fn is_empty<'txn>(&self, txn: &'txn RoTxn) -> Result { self.dyndb.is_empty(txn) } @@ -595,8 +591,8 @@ impl Database { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn iter<'txn, T>(&self, txn: &'txn RoTxn) -> Result> { - self.dyndb.iter::(txn) + pub fn iter<'txn>(&self, txn: &'txn RoTxn) -> Result> { + self.dyndb.iter::(txn) } /// Return a mutable lexicographically ordered iterator of all key-value pairs in this database. @@ -648,8 +644,8 @@ impl Database { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn iter_mut<'txn, T>(&self, txn: &'txn mut RwTxn) -> Result> { - self.dyndb.iter_mut::(txn) + pub fn iter_mut<'txn>(&self, txn: &'txn mut RwTxn) -> Result> { + self.dyndb.iter_mut::(txn) } /// Return a reversed lexicographically ordered iterator of all key-value pairs in this database. @@ -688,8 +684,8 @@ impl Database { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn rev_iter<'txn, T>(&self, txn: &'txn RoTxn) -> Result> { - self.dyndb.rev_iter::(txn) + pub fn rev_iter<'txn>(&self, txn: &'txn RoTxn) -> Result> { + self.dyndb.rev_iter::(txn) } /// Return a mutable reversed lexicographically ordered iterator of all key-value\ @@ -742,11 +738,8 @@ impl Database { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn rev_iter_mut<'txn, T>( - &self, - txn: &'txn mut RwTxn, - ) -> Result> { - self.dyndb.rev_iter_mut::(txn) + pub fn rev_iter_mut<'txn>(&self, txn: &'txn mut RwTxn) -> Result> { + self.dyndb.rev_iter_mut::(txn) } /// Return a lexicographically ordered iterator of a range of key-value pairs in this database. @@ -788,16 +781,16 @@ impl Database { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn range<'a, 'txn, T, R>( + pub fn range<'a, 'txn, R>( &self, - txn: &'txn RoTxn, + txn: &'txn RoTxn, range: &'a R, ) -> Result> where KC: BytesEncode<'a>, R: RangeBounds, { - self.dyndb.range::(txn, range) + self.dyndb.range::(txn, range) } /// Return a mutable lexicographically ordered iterator of a range of @@ -853,16 +846,16 @@ impl Database { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn range_mut<'a, 'txn, T, R>( + pub fn range_mut<'a, 'txn, R>( &self, - txn: &'txn mut RwTxn, + txn: &'txn mut RwTxn, range: &'a R, ) -> Result> where KC: BytesEncode<'a>, R: RangeBounds, { - self.dyndb.range_mut::(txn, range) + self.dyndb.range_mut::(txn, range) } /// Return a reversed lexicographically ordered iterator of a range of key-value @@ -905,16 +898,16 @@ impl Database { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn rev_range<'a, 'txn, T, R>( + pub fn rev_range<'a, 'txn, R>( &self, - txn: &'txn RoTxn, + txn: &'txn RoTxn, range: &'a R, ) -> Result> where KC: BytesEncode<'a>, R: RangeBounds, { - self.dyndb.rev_range::(txn, range) + self.dyndb.rev_range::(txn, range) } /// Return a mutable reversed lexicographically ordered iterator of a range of @@ -970,16 +963,16 @@ impl Database { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn rev_range_mut<'a, 'txn, T, R>( + pub fn rev_range_mut<'a, 'txn, R>( &self, - txn: &'txn mut RwTxn, + txn: &'txn mut RwTxn, range: &'a R, ) -> Result> where KC: BytesEncode<'a>, R: RangeBounds, { - self.dyndb.rev_range_mut::(txn, range) + self.dyndb.rev_range_mut::(txn, range) } /// Return a lexicographically ordered iterator of all key-value pairs @@ -1023,15 +1016,15 @@ impl Database { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn prefix_iter<'a, 'txn, T>( + pub fn prefix_iter<'a, 'txn>( &self, - txn: &'txn RoTxn, + txn: &'txn RoTxn, prefix: &'a KC::EItem, ) -> Result> where KC: BytesEncode<'a>, { - self.dyndb.prefix_iter::(txn, prefix) + self.dyndb.prefix_iter::(txn, prefix) } /// Return a mutable lexicographically ordered iterator of all key-value pairs @@ -1088,15 +1081,15 @@ impl Database { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn prefix_iter_mut<'a, 'txn, T>( + pub fn prefix_iter_mut<'a, 'txn>( &self, - txn: &'txn mut RwTxn, + txn: &'txn mut RwTxn, prefix: &'a KC::EItem, ) -> Result> where KC: BytesEncode<'a>, { - self.dyndb.prefix_iter_mut::(txn, prefix) + self.dyndb.prefix_iter_mut::(txn, prefix) } /// Return a reversed lexicographically ordered iterator of all key-value pairs @@ -1140,15 +1133,15 @@ impl Database { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn rev_prefix_iter<'a, 'txn, T>( + pub fn rev_prefix_iter<'a, 'txn>( &self, - txn: &'txn RoTxn, + txn: &'txn RoTxn, prefix: &'a KC::EItem, ) -> Result> where KC: BytesEncode<'a>, { - self.dyndb.rev_prefix_iter::(txn, prefix) + self.dyndb.rev_prefix_iter::(txn, prefix) } /// Return a mutable reversed lexicographically ordered iterator of all key-value pairs @@ -1205,15 +1198,15 @@ impl Database { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn rev_prefix_iter_mut<'a, 'txn, T>( + pub fn rev_prefix_iter_mut<'a, 'txn>( &self, - txn: &'txn mut RwTxn, + txn: &'txn mut RwTxn, prefix: &'a KC::EItem, ) -> Result> where KC: BytesEncode<'a>, { - self.dyndb.rev_prefix_iter_mut::(txn, prefix) + self.dyndb.rev_prefix_iter_mut::(txn, prefix) } /// Insert a key-value pairs in this database. @@ -1249,17 +1242,12 @@ impl Database { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn put<'a, T>( - &self, - txn: &mut RwTxn, - key: &'a KC::EItem, - data: &'a DC::EItem, - ) -> Result<()> + pub fn put<'a>(&self, txn: &mut RwTxn, key: &'a KC::EItem, data: &'a DC::EItem) -> Result<()> where KC: BytesEncode<'a>, DC: BytesEncode<'a>, { - self.dyndb.put::(txn, key, data) + self.dyndb.put::(txn, key, data) } /// Append the given key/data pair to the end of the database. @@ -1298,17 +1286,12 @@ impl Database { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn append<'a, T>( - &self, - txn: &mut RwTxn, - key: &'a KC::EItem, - data: &'a DC::EItem, - ) -> Result<()> + pub fn append<'a>(&self, txn: &mut RwTxn, key: &'a KC::EItem, data: &'a DC::EItem) -> Result<()> where KC: BytesEncode<'a>, DC: BytesEncode<'a>, { - self.dyndb.append::(txn, key, data) + self.dyndb.append::(txn, key, data) } /// Deletes a key-value pairs in this database. @@ -1352,11 +1335,11 @@ impl Database { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn delete<'a, T>(&self, txn: &mut RwTxn, key: &'a KC::EItem) -> Result + pub fn delete<'a>(&self, txn: &mut RwTxn, key: &'a KC::EItem) -> Result where KC: BytesEncode<'a>, { - self.dyndb.delete::(txn, key) + self.dyndb.delete::(txn, key) } /// Deletes a range of key-value pairs in this database. @@ -1407,16 +1390,12 @@ impl Database { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn delete_range<'a, 'txn, T, R>( - &self, - txn: &'txn mut RwTxn, - range: &'a R, - ) -> Result + pub fn delete_range<'a, 'txn, R>(&self, txn: &'txn mut RwTxn, range: &'a R) -> Result where KC: BytesEncode<'a> + BytesDecode<'txn>, R: RangeBounds, { - self.dyndb.delete_range::(txn, range) + self.dyndb.delete_range::(txn, range) } /// Deletes all key/value pairs in this database. @@ -1459,7 +1438,7 @@ impl Database { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn clear(&self, txn: &mut RwTxn) -> Result<()> { + pub fn clear(&self, txn: &mut RwTxn) -> Result<()> { self.dyndb.clear(txn) } @@ -1563,7 +1542,7 @@ impl Database { /// db.put(&mut wtxn, &BEI32::new(521), "i-am-five-hundred-and-twenty-one")?; /// /// // Check if a key exists and skip potentially expensive deserializing - /// let ret = db.as_polymorph().get::<_, OwnedType, DecodeIgnore>(&wtxn, &BEI32::new(42))?; + /// let ret = db.as_polymorph().get::, DecodeIgnore>(&wtxn, &BEI32::new(42))?; /// assert!(ret.is_some()); /// /// wtxn.commit()?; diff --git a/heed/src/env.rs b/heed/src/env.rs index 4dcf2d8a..66b59acc 100644 --- a/heed/src/env.rs +++ b/heed/src/env.rs @@ -418,14 +418,7 @@ impl Env { RwTxn::new(self) } - pub fn typed_write_txn(&self) -> Result> { - RwTxn::::new(self) - } - - pub fn nested_write_txn<'e, 'p: 'e, T>( - &'e self, - parent: &'p mut RwTxn, - ) -> Result> { + pub fn nested_write_txn<'e, 'p: 'e>(&'e self, parent: &'p mut RwTxn) -> Result> { RwTxn::nested(self, parent) } @@ -433,10 +426,6 @@ impl Env { RoTxn::new(self) } - pub fn typed_read_txn(&self) -> Result> { - RoTxn::new(self) - } - // TODO rename into `copy_to_file` for more clarity pub fn copy_to_path>(&self, path: P, option: CompactionOption) -> Result { let file = File::options().create_new(true).write(true).open(&path)?; diff --git a/heed/src/txn.rs b/heed/src/txn.rs index b6f9c202..0bdd9317 100644 --- a/heed/src/txn.rs +++ b/heed/src/txn.rs @@ -5,14 +5,13 @@ use crate::mdb::error::mdb_result; use crate::mdb::ffi; use crate::{Env, Result}; -pub struct RoTxn<'e, T = ()> { +pub struct RoTxn<'e> { pub(crate) txn: *mut ffi::MDB_txn, pub(crate) env: &'e Env, - _phantom: marker::PhantomData, } -impl<'e, T> RoTxn<'e, T> { - pub(crate) fn new(env: &'e Env) -> Result> { +impl<'e> RoTxn<'e> { + pub(crate) fn new(env: &'e Env) -> Result> { let mut txn: *mut ffi::MDB_txn = ptr::null_mut(); unsafe { @@ -24,7 +23,7 @@ impl<'e, T> RoTxn<'e, T> { ))? }; - Ok(RoTxn { txn, env, _phantom: marker::PhantomData }) + Ok(RoTxn { txn, env }) } pub fn commit(mut self) -> Result<()> { @@ -40,7 +39,7 @@ impl<'e, T> RoTxn<'e, T> { } } -impl Drop for RoTxn<'_, T> { +impl Drop for RoTxn<'_> { fn drop(&mut self) { if !self.txn.is_null() { let _ = abort_txn(self.txn); @@ -49,7 +48,7 @@ impl Drop for RoTxn<'_, T> { } #[cfg(feature = "sync-read-txn")] -unsafe impl Sync for RoTxn<'_, T> {} +unsafe impl Sync for RoTxn<'_> {} fn abort_txn(txn: *mut ffi::MDB_txn) -> Result<()> { // Asserts that the transaction hasn't been already committed. @@ -57,36 +56,27 @@ fn abort_txn(txn: *mut ffi::MDB_txn) -> Result<()> { Ok(unsafe { ffi::mdb_txn_abort(txn) }) } -pub struct RwTxn<'e, 'p, T = ()> { - pub(crate) txn: RoTxn<'e, T>, +pub struct RwTxn<'e, 'p> { + pub(crate) txn: RoTxn<'e>, _parent: marker::PhantomData<&'p mut ()>, } -impl<'e, T> RwTxn<'e, 'e, T> { - pub(crate) fn new(env: &'e Env) -> Result> { +impl<'e> RwTxn<'e, 'e> { + pub(crate) fn new(env: &'e Env) -> Result> { let mut txn: *mut ffi::MDB_txn = ptr::null_mut(); unsafe { mdb_result(ffi::mdb_txn_begin(env.env_mut_ptr(), ptr::null_mut(), 0, &mut txn))? }; - Ok(RwTxn { - txn: RoTxn { txn, env, _phantom: marker::PhantomData }, - _parent: marker::PhantomData, - }) + Ok(RwTxn { txn: RoTxn { txn, env }, _parent: marker::PhantomData }) } - pub(crate) fn nested<'p: 'e>( - env: &'e Env, - parent: &'p mut RwTxn, - ) -> Result> { + pub(crate) fn nested<'p: 'e>(env: &'e Env, parent: &'p mut RwTxn) -> Result> { let mut txn: *mut ffi::MDB_txn = ptr::null_mut(); let parent_ptr: *mut ffi::MDB_txn = parent.txn.txn; unsafe { mdb_result(ffi::mdb_txn_begin(env.env_mut_ptr(), parent_ptr, 0, &mut txn))? }; - Ok(RwTxn { - txn: RoTxn { txn, env, _phantom: marker::PhantomData }, - _parent: marker::PhantomData, - }) + Ok(RwTxn { txn: RoTxn { txn, env }, _parent: marker::PhantomData }) } pub fn commit(self) -> Result<()> { @@ -98,8 +88,8 @@ impl<'e, T> RwTxn<'e, 'e, T> { } } -impl<'e, 'p, T> Deref for RwTxn<'e, 'p, T> { - type Target = RoTxn<'e, T>; +impl<'e, 'p> Deref for RwTxn<'e, 'p> { + type Target = RoTxn<'e>; fn deref(&self) -> &Self::Target { &self.txn From f1ce77e4b67b0ed6cd9dc27365fc19758af8c57e Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Wed, 6 Jul 2022 18:09:11 +0200 Subject: [PATCH 08/57] Use mdb_stat for db.len() Closes #56 --- heed/src/db/polymorph.rs | 22 ++++++++++------------ heed/src/db/uniform.rs | 2 +- heed/src/mdb/lmdb_ffi.rs | 6 +++--- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/heed/src/db/polymorph.rs b/heed/src/db/polymorph.rs index 26b1a54e..354fdd12 100644 --- a/heed/src/db/polymorph.rs +++ b/heed/src/db/polymorph.rs @@ -596,24 +596,22 @@ impl PolyDatabase { /// assert_eq!(ret, 3); /// /// wtxn.commit()?; + /// /// # Ok(()) } /// ``` - pub fn len<'txn>(&self, txn: &'txn RoTxn) -> Result { + pub fn len<'txn>(&self, txn: &'txn RoTxn) -> Result { assert_eq!(self.env_ident, txn.env.env_mut_ptr() as usize); - let mut cursor = RoCursor::new(txn, self.dbi)?; - let mut count = 0; + let mut db_stat = mem::MaybeUninit::uninit(); + let result = unsafe { mdb_result(ffi::mdb_stat(txn.txn, self.dbi, db_stat.as_mut_ptr())) }; - match cursor.move_on_first()? { - Some(_) => count += 1, - None => return Ok(0), - } - - while let Some(_) = cursor.move_on_next()? { - count += 1; + match result { + Ok(()) => { + let stats = unsafe { db_stat.assume_init() }; + Ok(stats.ms_entries as u64) + } + Err(e) => Err(e.into()), } - - Ok(count) } /// Returns `true` if and only if this database is empty. diff --git a/heed/src/db/uniform.rs b/heed/src/db/uniform.rs index 4e661678..fd018ee5 100644 --- a/heed/src/db/uniform.rs +++ b/heed/src/db/uniform.rs @@ -509,7 +509,7 @@ impl Database { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn len<'txn>(&self, txn: &'txn RoTxn) -> Result { + pub fn len<'txn>(&self, txn: &'txn RoTxn) -> Result { self.dyndb.len(txn) } diff --git a/heed/src/mdb/lmdb_ffi.rs b/heed/src/mdb/lmdb_ffi.rs index 06bc0a88..f4de552c 100644 --- a/heed/src/mdb/lmdb_ffi.rs +++ b/heed/src/mdb/lmdb_ffi.rs @@ -2,9 +2,9 @@ pub use ffi::{ mdb_cursor_close, mdb_cursor_del, mdb_cursor_get, mdb_cursor_open, mdb_cursor_put, mdb_dbi_open, mdb_del, mdb_drop, mdb_env_close, mdb_env_copyfd2 as mdb_env_copy2fd, mdb_env_create, mdb_env_open, mdb_env_set_mapsize, mdb_env_set_maxdbs, mdb_env_set_maxreaders, - mdb_env_sync, mdb_filehandle_t, mdb_get, mdb_put, mdb_txn_abort, mdb_txn_begin, mdb_txn_commit, - MDB_cursor, MDB_dbi, MDB_env, MDB_txn, MDB_APPEND, MDB_CP_COMPACT, MDB_CREATE, MDB_CURRENT, - MDB_RDONLY, + mdb_env_stat, mdb_env_sync, mdb_filehandle_t, mdb_get, mdb_put, mdb_stat, mdb_txn_abort, + mdb_txn_begin, mdb_txn_commit, MDB_cursor, MDB_dbi, MDB_env, MDB_stat as MDB_Stat, MDB_txn, + MDB_APPEND, MDB_CP_COMPACT, MDB_CREATE, MDB_CURRENT, MDB_RDONLY, }; use lmdb_master3_sys as ffi; From df8b2d86e1e34ce9a4eceda97eae1b8fc89212ac Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Wed, 6 Jul 2022 18:08:12 +0200 Subject: [PATCH 09/57] Compute an error when encoding/decoding in bytes --- heed-traits/src/lib.rs | 8 ++- heed-types/Cargo.toml | 2 +- heed-types/src/cow_slice.rs | 14 ++--- heed-types/src/cow_type.rs | 14 ++--- heed-types/src/lib.rs | 6 ++- heed-types/src/owned_slice.rs | 8 +-- heed-types/src/owned_type.rs | 8 +-- heed-types/src/serde_bincode.rs | 10 ++-- heed-types/src/serde_json.rs | 10 ++-- heed-types/src/str.rs | 10 ++-- heed-types/src/unaligned_slice.rs | 10 ++-- heed-types/src/unaligned_type.rs | 10 ++-- heed-types/src/unit.rs | 13 ++--- heed/src/db/polymorph.rs | 86 +++++++++++++++---------------- heed/src/iter/iter.rs | 48 ++++++++--------- heed/src/iter/prefix.rs | 48 ++++++++--------- heed/src/iter/range.rs | 48 ++++++++--------- heed/src/lazy_decode.rs | 10 ++-- heed/src/lib.rs | 10 ++-- 19 files changed, 190 insertions(+), 183 deletions(-) diff --git a/heed-traits/src/lib.rs b/heed-traits/src/lib.rs index 4f1b9227..66c883db 100644 --- a/heed-traits/src/lib.rs +++ b/heed-traits/src/lib.rs @@ -1,13 +1,17 @@ use std::borrow::Cow; +use std::error::Error as StdError; + +/// A boxed `Send + Sync + 'static` error. +pub type BoxedError = Box; pub trait BytesEncode<'a> { type EItem: ?Sized + 'a; - fn bytes_encode(item: &'a Self::EItem) -> Option>; + fn bytes_encode(item: &'a Self::EItem) -> Result, BoxedError>; } pub trait BytesDecode<'a> { type DItem: 'a; - fn bytes_decode(bytes: &'a [u8]) -> Option; + fn bytes_decode(bytes: &'a [u8]) -> Result; } diff --git a/heed-types/Cargo.toml b/heed-types/Cargo.toml index 99309edf..d207ad9b 100644 --- a/heed-types/Cargo.toml +++ b/heed-types/Cargo.toml @@ -10,7 +10,7 @@ edition = "2018" [dependencies] bincode = { version = "1.2.1", optional = true } -bytemuck = { version = "1.5.0", features = ["extern_crate_alloc"] } +bytemuck = { version = "1.5.0", features = ["extern_crate_alloc", "extern_crate_std"] } byteorder = "1.4.2" heed-traits = { version = "0.7.0", path = "../heed-traits" } serde = { version = "1.0.117", optional = true } diff --git a/heed-types/src/cow_slice.rs b/heed-types/src/cow_slice.rs index 64d161a6..48f30b19 100644 --- a/heed-types/src/cow_slice.rs +++ b/heed-types/src/cow_slice.rs @@ -1,7 +1,7 @@ use std::borrow::Cow; use bytemuck::{pod_collect_to_vec, try_cast_slice, AnyBitPattern, NoUninit, PodCastError}; -use heed_traits::{BytesDecode, BytesEncode}; +use heed_traits::{BoxedError, BytesDecode, BytesEncode}; /// Describes a slice that must be [memory aligned] and /// will be reallocated if it is not. @@ -23,19 +23,19 @@ pub struct CowSlice(std::marker::PhantomData); impl<'a, T: NoUninit> BytesEncode<'a> for CowSlice { type EItem = [T]; - fn bytes_encode(item: &'a Self::EItem) -> Option> { - try_cast_slice(item).map(Cow::Borrowed).ok() + fn bytes_encode(item: &'a Self::EItem) -> Result, BoxedError> { + try_cast_slice(item).map(Cow::Borrowed).map_err(Into::into) } } impl<'a, T: AnyBitPattern + NoUninit> BytesDecode<'a> for CowSlice { type DItem = Cow<'a, [T]>; - fn bytes_decode(bytes: &'a [u8]) -> Option { + fn bytes_decode(bytes: &'a [u8]) -> Result { match try_cast_slice(bytes) { - Ok(items) => Some(Cow::Borrowed(items)), - Err(PodCastError::AlignmentMismatch) => Some(Cow::Owned(pod_collect_to_vec(bytes))), - Err(_) => None, + Ok(items) => Ok(Cow::Borrowed(items)), + Err(PodCastError::AlignmentMismatch) => Ok(Cow::Owned(pod_collect_to_vec(bytes))), + Err(error) => Err(error.into()), } } } diff --git a/heed-types/src/cow_type.rs b/heed-types/src/cow_type.rs index 8282dfb7..7f4ff151 100644 --- a/heed-types/src/cow_type.rs +++ b/heed-types/src/cow_type.rs @@ -1,7 +1,7 @@ use std::borrow::Cow; use bytemuck::{bytes_of, bytes_of_mut, try_from_bytes, AnyBitPattern, NoUninit, PodCastError}; -use heed_traits::{BytesDecode, BytesEncode}; +use heed_traits::{BoxedError, BytesDecode, BytesEncode}; /// Describes a type that must be [memory aligned] and /// will be reallocated if it is not. @@ -29,23 +29,23 @@ pub struct CowType(std::marker::PhantomData); impl<'a, T: NoUninit> BytesEncode<'a> for CowType { type EItem = T; - fn bytes_encode(item: &'a Self::EItem) -> Option> { - Some(Cow::Borrowed(bytes_of(item))) + fn bytes_encode(item: &'a Self::EItem) -> Result, BoxedError> { + Ok(Cow::Borrowed(bytes_of(item))) } } impl<'a, T: AnyBitPattern + NoUninit> BytesDecode<'a> for CowType { type DItem = Cow<'a, T>; - fn bytes_decode(bytes: &'a [u8]) -> Option { + fn bytes_decode(bytes: &'a [u8]) -> Result { match try_from_bytes(bytes) { - Ok(item) => Some(Cow::Borrowed(item)), + Ok(item) => Ok(Cow::Borrowed(item)), Err(PodCastError::TargetAlignmentGreaterAndInputNotAligned) => { let mut item = T::zeroed(); bytes_of_mut(&mut item).copy_from_slice(bytes); - Some(Cow::Owned(item)) + Ok(Cow::Owned(item)) } - Err(_) => None, + Err(error) => Err(error.into()), } } } diff --git a/heed-types/src/lib.rs b/heed-types/src/lib.rs index b65ce519..68596753 100644 --- a/heed-types/src/lib.rs +++ b/heed-types/src/lib.rs @@ -37,6 +37,8 @@ mod serde_bincode; #[cfg(feature = "serde-json")] mod serde_json; +use heed_traits::BoxedError; + pub use self::cow_slice::CowSlice; pub use self::cow_type::CowType; pub use self::integer::*; @@ -62,8 +64,8 @@ pub struct DecodeIgnore; impl heed_traits::BytesDecode<'_> for DecodeIgnore { type DItem = (); - fn bytes_decode(_bytes: &[u8]) -> Option { - Some(()) + fn bytes_decode(_bytes: &[u8]) -> Result { + Ok(()) } } diff --git a/heed-types/src/owned_slice.rs b/heed-types/src/owned_slice.rs index c566f436..6b442793 100644 --- a/heed-types/src/owned_slice.rs +++ b/heed-types/src/owned_slice.rs @@ -1,7 +1,7 @@ use std::borrow::Cow; use bytemuck::{try_cast_slice, AnyBitPattern, NoUninit}; -use heed_traits::{BytesDecode, BytesEncode}; +use heed_traits::{BoxedError, BytesDecode, BytesEncode}; use crate::CowSlice; @@ -23,15 +23,15 @@ pub struct OwnedSlice(std::marker::PhantomData); impl<'a, T: NoUninit> BytesEncode<'a> for OwnedSlice { type EItem = [T]; - fn bytes_encode(item: &'a Self::EItem) -> Option> { - try_cast_slice(item).map(Cow::Borrowed).ok() + fn bytes_encode(item: &'a Self::EItem) -> Result, BoxedError> { + try_cast_slice(item).map(Cow::Borrowed).map_err(Into::into) } } impl<'a, T: AnyBitPattern + NoUninit> BytesDecode<'a> for OwnedSlice { type DItem = Vec; - fn bytes_decode(bytes: &[u8]) -> Option { + fn bytes_decode(bytes: &[u8]) -> Result { CowSlice::::bytes_decode(bytes).map(Cow::into_owned) } } diff --git a/heed-types/src/owned_type.rs b/heed-types/src/owned_type.rs index a88bc0e1..aa890bae 100644 --- a/heed-types/src/owned_type.rs +++ b/heed-types/src/owned_type.rs @@ -1,7 +1,7 @@ use std::borrow::Cow; use bytemuck::{bytes_of, AnyBitPattern, NoUninit}; -use heed_traits::{BytesDecode, BytesEncode}; +use heed_traits::{BoxedError, BytesDecode, BytesEncode}; use crate::CowType; @@ -29,15 +29,15 @@ pub struct OwnedType(std::marker::PhantomData); impl<'a, T: NoUninit> BytesEncode<'a> for OwnedType { type EItem = T; - fn bytes_encode(item: &'a Self::EItem) -> Option> { - Some(Cow::Borrowed(bytes_of(item))) + fn bytes_encode(item: &'a Self::EItem) -> Result, BoxedError> { + Ok(Cow::Borrowed(bytes_of(item))) } } impl<'a, T: AnyBitPattern + NoUninit> BytesDecode<'a> for OwnedType { type DItem = T; - fn bytes_decode(bytes: &[u8]) -> Option { + fn bytes_decode(bytes: &[u8]) -> Result { CowType::::bytes_decode(bytes).map(Cow::into_owned) } } diff --git a/heed-types/src/serde_bincode.rs b/heed-types/src/serde_bincode.rs index 464aceb4..37fefe01 100644 --- a/heed-types/src/serde_bincode.rs +++ b/heed-types/src/serde_bincode.rs @@ -1,6 +1,6 @@ use std::borrow::Cow; -use heed_traits::{BytesDecode, BytesEncode}; +use heed_traits::{BoxedError, BytesDecode, BytesEncode}; use serde::{Deserialize, Serialize}; /// Describes a type that is [`Serialize`]/[`Deserialize`] and uses `bincode` to do so. @@ -14,8 +14,8 @@ where { type EItem = T; - fn bytes_encode(item: &'a Self::EItem) -> Option> { - bincode::serialize(item).map(Cow::Owned).ok() + fn bytes_encode(item: &'a Self::EItem) -> Result, BoxedError> { + bincode::serialize(item).map(Cow::Owned).map_err(Into::into) } } @@ -25,8 +25,8 @@ where { type DItem = T; - fn bytes_decode(bytes: &'a [u8]) -> Option { - bincode::deserialize(bytes).ok() + fn bytes_decode(bytes: &'a [u8]) -> Result { + bincode::deserialize(bytes).map_err(Into::into) } } diff --git a/heed-types/src/serde_json.rs b/heed-types/src/serde_json.rs index 2327e259..f1f1c3be 100644 --- a/heed-types/src/serde_json.rs +++ b/heed-types/src/serde_json.rs @@ -1,6 +1,6 @@ use std::borrow::Cow; -use heed_traits::{BytesDecode, BytesEncode}; +use heed_traits::{BoxedError, BytesDecode, BytesEncode}; use serde::{Deserialize, Serialize}; /// Describes a type that is [`Serialize`]/[`Deserialize`] and uses `serde_json` to do so. @@ -14,8 +14,8 @@ where { type EItem = T; - fn bytes_encode(item: &Self::EItem) -> Option> { - serde_json::to_vec(item).map(Cow::Owned).ok() + fn bytes_encode(item: &Self::EItem) -> Result, BoxedError> { + serde_json::to_vec(item).map(Cow::Owned).map_err(Into::into) } } @@ -25,8 +25,8 @@ where { type DItem = T; - fn bytes_decode(bytes: &'a [u8]) -> Option { - serde_json::from_slice(bytes).ok() + fn bytes_decode(bytes: &'a [u8]) -> Result { + serde_json::from_slice(bytes).map_err(Into::into) } } diff --git a/heed-types/src/str.rs b/heed-types/src/str.rs index 9c40c542..4d00ef2e 100644 --- a/heed-types/src/str.rs +++ b/heed-types/src/str.rs @@ -1,6 +1,6 @@ use std::borrow::Cow; -use heed_traits::{BytesDecode, BytesEncode}; +use heed_traits::{BoxedError, BytesDecode, BytesEncode}; /// Describes an [`prim@str`]. pub struct Str; @@ -8,15 +8,15 @@ pub struct Str; impl BytesEncode<'_> for Str { type EItem = str; - fn bytes_encode(item: &Self::EItem) -> Option> { - Some(Cow::Borrowed(item.as_bytes())) + fn bytes_encode(item: &Self::EItem) -> Result, BoxedError> { + Ok(Cow::Borrowed(item.as_bytes())) } } impl<'a> BytesDecode<'a> for Str { type DItem = &'a str; - fn bytes_decode(bytes: &'a [u8]) -> Option { - std::str::from_utf8(bytes).ok() + fn bytes_decode(bytes: &'a [u8]) -> Result { + std::str::from_utf8(bytes).map_err(Into::into) } } diff --git a/heed-types/src/unaligned_slice.rs b/heed-types/src/unaligned_slice.rs index 3ab36943..7d13a1df 100644 --- a/heed-types/src/unaligned_slice.rs +++ b/heed-types/src/unaligned_slice.rs @@ -1,7 +1,7 @@ use std::borrow::Cow; use bytemuck::{try_cast_slice, AnyBitPattern, NoUninit}; -use heed_traits::{BytesDecode, BytesEncode}; +use heed_traits::{BoxedError, BytesDecode, BytesEncode}; /// Describes a type that is totally borrowed and doesn't /// depends on any [memory alignment]. @@ -16,16 +16,16 @@ pub struct UnalignedSlice(std::marker::PhantomData); impl<'a, T: NoUninit> BytesEncode<'a> for UnalignedSlice { type EItem = [T]; - fn bytes_encode(item: &'a Self::EItem) -> Option> { - try_cast_slice(item).map(Cow::Borrowed).ok() + fn bytes_encode(item: &'a Self::EItem) -> Result, BoxedError> { + try_cast_slice(item).map(Cow::Borrowed).map_err(Into::into) } } impl<'a, T: AnyBitPattern> BytesDecode<'a> for UnalignedSlice { type DItem = &'a [T]; - fn bytes_decode(bytes: &'a [u8]) -> Option { - try_cast_slice(bytes).ok() + fn bytes_decode(bytes: &'a [u8]) -> Result { + try_cast_slice(bytes).map_err(Into::into) } } diff --git a/heed-types/src/unaligned_type.rs b/heed-types/src/unaligned_type.rs index f2756a9b..886aeceb 100644 --- a/heed-types/src/unaligned_type.rs +++ b/heed-types/src/unaligned_type.rs @@ -1,7 +1,7 @@ use std::borrow::Cow; use bytemuck::{bytes_of, try_from_bytes, AnyBitPattern, NoUninit}; -use heed_traits::{BytesDecode, BytesEncode}; +use heed_traits::{BoxedError, BytesDecode, BytesEncode}; /// Describes a slice that is totally borrowed and doesn't /// depends on any [memory alignment]. @@ -22,16 +22,16 @@ pub struct UnalignedType(std::marker::PhantomData); impl<'a, T: NoUninit> BytesEncode<'a> for UnalignedType { type EItem = T; - fn bytes_encode(item: &'a Self::EItem) -> Option> { - Some(Cow::Borrowed(bytes_of(item))) + fn bytes_encode(item: &'a Self::EItem) -> Result, BoxedError> { + Ok(Cow::Borrowed(bytes_of(item))) } } impl<'a, T: AnyBitPattern> BytesDecode<'a> for UnalignedType { type DItem = &'a T; - fn bytes_decode(bytes: &'a [u8]) -> Option { - try_from_bytes(bytes).ok() + fn bytes_decode(bytes: &'a [u8]) -> Result { + try_from_bytes(bytes).map_err(Into::into) } } diff --git a/heed-types/src/unit.rs b/heed-types/src/unit.rs index f53152ae..fee8bd56 100644 --- a/heed-types/src/unit.rs +++ b/heed-types/src/unit.rs @@ -1,6 +1,7 @@ use std::borrow::Cow; -use heed_traits::{BytesDecode, BytesEncode}; +use bytemuck::PodCastError; +use heed_traits::{BoxedError, BytesDecode, BytesEncode}; /// Describes the `()` type. pub struct Unit; @@ -8,19 +9,19 @@ pub struct Unit; impl BytesEncode<'_> for Unit { type EItem = (); - fn bytes_encode(_item: &Self::EItem) -> Option> { - Some(Cow::Borrowed(&[])) + fn bytes_encode(_item: &Self::EItem) -> Result, BoxedError> { + Ok(Cow::Borrowed(&[])) } } impl BytesDecode<'_> for Unit { type DItem = (); - fn bytes_decode(bytes: &[u8]) -> Option { + fn bytes_decode(bytes: &[u8]) -> Result { if bytes.is_empty() { - Some(()) + Ok(()) } else { - None + Err(PodCastError::SizeMismatch.into()) } } } diff --git a/heed/src/db/polymorph.rs b/heed/src/db/polymorph.rs index 354fdd12..2453a665 100644 --- a/heed/src/db/polymorph.rs +++ b/heed/src/db/polymorph.rs @@ -157,7 +157,7 @@ impl PolyDatabase { { assert_eq!(self.env_ident, txn.env.env_mut_ptr() as usize); - let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).ok_or(Error::Encoding)?; + let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).map_err(Error::Encoding)?; let mut key_val = unsafe { crate::into_val(&key_bytes) }; let mut data_val = mem::MaybeUninit::uninit(); @@ -169,7 +169,7 @@ impl PolyDatabase { match result { Ok(()) => { let data = unsafe { crate::from_val(data_val.assume_init()) }; - let data = DC::bytes_decode(data).ok_or(Error::Decoding)?; + let data = DC::bytes_decode(data).map_err(Error::Decoding)?; Ok(Some(data)) } Err(e) if e.not_found() => Ok(None), @@ -232,13 +232,13 @@ impl PolyDatabase { assert_eq!(self.env_ident, txn.env.env_mut_ptr() as usize); let mut cursor = RoCursor::new(txn, self.dbi)?; - let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).ok_or(Error::Encoding)?; + let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).map_err(Error::Encoding)?; cursor.move_on_key_greater_than_or_equal_to(&key_bytes)?; match cursor.move_on_prev() { Ok(Some((key, data))) => match (KC::bytes_decode(key), DC::bytes_decode(data)) { - (Some(key), Some(data)) => Ok(Some((key, data))), - (_, _) => Err(Error::Decoding), + (Ok(key), Ok(data)) => Ok(Some((key, data))), + (Err(e), _) | (_, Err(e)) => Err(Error::Decoding(e)), }, Ok(None) => Ok(None), Err(e) => Err(e), @@ -300,7 +300,7 @@ impl PolyDatabase { assert_eq!(self.env_ident, txn.env.env_mut_ptr() as usize); let mut cursor = RoCursor::new(txn, self.dbi)?; - let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).ok_or(Error::Encoding)?; + let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).map_err(Error::Encoding)?; let result = match cursor.move_on_key_greater_than_or_equal_to(&key_bytes) { Ok(Some((key, data))) if key == &key_bytes[..] => Ok(Some((key, data))), Ok(_) => cursor.move_on_prev(), @@ -309,8 +309,8 @@ impl PolyDatabase { match result { Ok(Some((key, data))) => match (KC::bytes_decode(key), DC::bytes_decode(data)) { - (Some(key), Some(data)) => Ok(Some((key, data))), - (_, _) => Err(Error::Decoding), + (Ok(key), Ok(data)) => Ok(Some((key, data))), + (Err(e), _) | (_, Err(e)) => Err(Error::Decoding(e)), }, Ok(None) => Ok(None), Err(e) => Err(e), @@ -372,7 +372,7 @@ impl PolyDatabase { assert_eq!(self.env_ident, txn.env.env_mut_ptr() as usize); let mut cursor = RoCursor::new(txn, self.dbi)?; - let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).ok_or(Error::Encoding)?; + let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).map_err(Error::Encoding)?; let entry = match cursor.move_on_key_greater_than_or_equal_to(&key_bytes)? { Some((key, data)) if key > &key_bytes[..] => Some((key, data)), Some((_key, _data)) => cursor.move_on_next()?, @@ -381,8 +381,8 @@ impl PolyDatabase { match entry { Some((key, data)) => match (KC::bytes_decode(key), DC::bytes_decode(data)) { - (Some(key), Some(data)) => Ok(Some((key, data))), - (_, _) => Err(Error::Decoding), + (Ok(key), Ok(data)) => Ok(Some((key, data))), + (Err(e), _) | (_, Err(e)) => Err(Error::Decoding(e)), }, None => Ok(None), } @@ -443,11 +443,11 @@ impl PolyDatabase { assert_eq!(self.env_ident, txn.env.env_mut_ptr() as usize); let mut cursor = RoCursor::new(txn, self.dbi)?; - let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).ok_or(Error::Encoding)?; + let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).map_err(Error::Encoding)?; match cursor.move_on_key_greater_than_or_equal_to(&key_bytes) { Ok(Some((key, data))) => match (KC::bytes_decode(key), DC::bytes_decode(data)) { - (Some(key), Some(data)) => Ok(Some((key, data))), - (_, _) => Err(Error::Decoding), + (Ok(key), Ok(data)) => Ok(Some((key, data))), + (Err(e), _) | (_, Err(e)) => Err(Error::Decoding(e)), }, Ok(None) => Ok(None), Err(e) => Err(e), @@ -499,8 +499,8 @@ impl PolyDatabase { let mut cursor = RoCursor::new(txn, self.dbi)?; match cursor.move_on_first() { Ok(Some((key, data))) => match (KC::bytes_decode(key), DC::bytes_decode(data)) { - (Some(key), Some(data)) => Ok(Some((key, data))), - (_, _) => Err(Error::Decoding), + (Ok(key), Ok(data)) => Ok(Some((key, data))), + (Err(e), _) | (_, Err(e)) => Err(Error::Decoding(e)), }, Ok(None) => Ok(None), Err(e) => Err(e), @@ -552,8 +552,8 @@ impl PolyDatabase { let mut cursor = RoCursor::new(txn, self.dbi)?; match cursor.move_on_last() { Ok(Some((key, data))) => match (KC::bytes_decode(key), DC::bytes_decode(data)) { - (Some(key), Some(data)) => Ok(Some((key, data))), - (_, _) => Err(Error::Decoding), + (Ok(key), Ok(data)) => Ok(Some((key, data))), + (Err(e), _) | (_, Err(e)) => Err(Error::Decoding(e)), }, Ok(None) => Ok(None), Err(e) => Err(e), @@ -912,11 +912,11 @@ impl PolyDatabase { let start_bound = match range.start_bound() { Bound::Included(bound) => { - let bytes = KC::bytes_encode(bound).ok_or(Error::Encoding)?; + let bytes = KC::bytes_encode(bound).map_err(Error::Encoding)?; Bound::Included(bytes.into_owned()) } Bound::Excluded(bound) => { - let bytes = KC::bytes_encode(bound).ok_or(Error::Encoding)?; + let bytes = KC::bytes_encode(bound).map_err(Error::Encoding)?; Bound::Excluded(bytes.into_owned()) } Bound::Unbounded => Bound::Unbounded, @@ -924,11 +924,11 @@ impl PolyDatabase { let end_bound = match range.end_bound() { Bound::Included(bound) => { - let bytes = KC::bytes_encode(bound).ok_or(Error::Encoding)?; + let bytes = KC::bytes_encode(bound).map_err(Error::Encoding)?; Bound::Included(bytes.into_owned()) } Bound::Excluded(bound) => { - let bytes = KC::bytes_encode(bound).ok_or(Error::Encoding)?; + let bytes = KC::bytes_encode(bound).map_err(Error::Encoding)?; Bound::Excluded(bytes.into_owned()) } Bound::Unbounded => Bound::Unbounded, @@ -1003,11 +1003,11 @@ impl PolyDatabase { let start_bound = match range.start_bound() { Bound::Included(bound) => { - let bytes = KC::bytes_encode(bound).ok_or(Error::Encoding)?; + let bytes = KC::bytes_encode(bound).map_err(Error::Encoding)?; Bound::Included(bytes.into_owned()) } Bound::Excluded(bound) => { - let bytes = KC::bytes_encode(bound).ok_or(Error::Encoding)?; + let bytes = KC::bytes_encode(bound).map_err(Error::Encoding)?; Bound::Excluded(bytes.into_owned()) } Bound::Unbounded => Bound::Unbounded, @@ -1015,11 +1015,11 @@ impl PolyDatabase { let end_bound = match range.end_bound() { Bound::Included(bound) => { - let bytes = KC::bytes_encode(bound).ok_or(Error::Encoding)?; + let bytes = KC::bytes_encode(bound).map_err(Error::Encoding)?; Bound::Included(bytes.into_owned()) } Bound::Excluded(bound) => { - let bytes = KC::bytes_encode(bound).ok_or(Error::Encoding)?; + let bytes = KC::bytes_encode(bound).map_err(Error::Encoding)?; Bound::Excluded(bytes.into_owned()) } Bound::Unbounded => Bound::Unbounded, @@ -1081,11 +1081,11 @@ impl PolyDatabase { let start_bound = match range.start_bound() { Bound::Included(bound) => { - let bytes = KC::bytes_encode(bound).ok_or(Error::Encoding)?; + let bytes = KC::bytes_encode(bound).map_err(Error::Encoding)?; Bound::Included(bytes.into_owned()) } Bound::Excluded(bound) => { - let bytes = KC::bytes_encode(bound).ok_or(Error::Encoding)?; + let bytes = KC::bytes_encode(bound).map_err(Error::Encoding)?; Bound::Excluded(bytes.into_owned()) } Bound::Unbounded => Bound::Unbounded, @@ -1093,11 +1093,11 @@ impl PolyDatabase { let end_bound = match range.end_bound() { Bound::Included(bound) => { - let bytes = KC::bytes_encode(bound).ok_or(Error::Encoding)?; + let bytes = KC::bytes_encode(bound).map_err(Error::Encoding)?; Bound::Included(bytes.into_owned()) } Bound::Excluded(bound) => { - let bytes = KC::bytes_encode(bound).ok_or(Error::Encoding)?; + let bytes = KC::bytes_encode(bound).map_err(Error::Encoding)?; Bound::Excluded(bytes.into_owned()) } Bound::Unbounded => Bound::Unbounded, @@ -1172,11 +1172,11 @@ impl PolyDatabase { let start_bound = match range.start_bound() { Bound::Included(bound) => { - let bytes = KC::bytes_encode(bound).ok_or(Error::Encoding)?; + let bytes = KC::bytes_encode(bound).map_err(Error::Encoding)?; Bound::Included(bytes.into_owned()) } Bound::Excluded(bound) => { - let bytes = KC::bytes_encode(bound).ok_or(Error::Encoding)?; + let bytes = KC::bytes_encode(bound).map_err(Error::Encoding)?; Bound::Excluded(bytes.into_owned()) } Bound::Unbounded => Bound::Unbounded, @@ -1184,11 +1184,11 @@ impl PolyDatabase { let end_bound = match range.end_bound() { Bound::Included(bound) => { - let bytes = KC::bytes_encode(bound).ok_or(Error::Encoding)?; + let bytes = KC::bytes_encode(bound).map_err(Error::Encoding)?; Bound::Included(bytes.into_owned()) } Bound::Excluded(bound) => { - let bytes = KC::bytes_encode(bound).ok_or(Error::Encoding)?; + let bytes = KC::bytes_encode(bound).map_err(Error::Encoding)?; Bound::Excluded(bytes.into_owned()) } Bound::Unbounded => Bound::Unbounded, @@ -1248,7 +1248,7 @@ impl PolyDatabase { { assert_eq!(self.env_ident, txn.env.env_mut_ptr() as usize); - let prefix_bytes = KC::bytes_encode(prefix).ok_or(Error::Encoding)?; + let prefix_bytes = KC::bytes_encode(prefix).map_err(Error::Encoding)?; let prefix_bytes = prefix_bytes.into_owned(); RoCursor::new(txn, self.dbi).map(|cursor| RoPrefix::new(cursor, prefix_bytes)) } @@ -1317,7 +1317,7 @@ impl PolyDatabase { { assert_eq!(self.env_ident, txn.txn.env.env_mut_ptr() as usize); - let prefix_bytes = KC::bytes_encode(prefix).ok_or(Error::Encoding)?; + let prefix_bytes = KC::bytes_encode(prefix).map_err(Error::Encoding)?; let prefix_bytes = prefix_bytes.into_owned(); RwCursor::new(txn, self.dbi).map(|cursor| RwPrefix::new(cursor, prefix_bytes)) } @@ -1373,7 +1373,7 @@ impl PolyDatabase { { assert_eq!(self.env_ident, txn.env.env_mut_ptr() as usize); - let prefix_bytes = KC::bytes_encode(prefix).ok_or(Error::Encoding)?; + let prefix_bytes = KC::bytes_encode(prefix).map_err(Error::Encoding)?; let prefix_bytes = prefix_bytes.into_owned(); RoCursor::new(txn, self.dbi).map(|cursor| RoRevPrefix::new(cursor, prefix_bytes)) } @@ -1442,7 +1442,7 @@ impl PolyDatabase { { assert_eq!(self.env_ident, txn.txn.env.env_mut_ptr() as usize); - let prefix_bytes = KC::bytes_encode(prefix).ok_or(Error::Encoding)?; + let prefix_bytes = KC::bytes_encode(prefix).map_err(Error::Encoding)?; let prefix_bytes = prefix_bytes.into_owned(); RwCursor::new(txn, self.dbi).map(|cursor| RwRevPrefix::new(cursor, prefix_bytes)) } @@ -1492,8 +1492,8 @@ impl PolyDatabase { { assert_eq!(self.env_ident, txn.txn.env.env_mut_ptr() as usize); - let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).ok_or(Error::Encoding)?; - let data_bytes: Cow<[u8]> = DC::bytes_encode(&data).ok_or(Error::Encoding)?; + let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).map_err(Error::Encoding)?; + let data_bytes: Cow<[u8]> = DC::bytes_encode(&data).map_err(Error::Encoding)?; let mut key_val = unsafe { crate::into_val(&key_bytes) }; let mut data_val = unsafe { crate::into_val(&data_bytes) }; @@ -1554,8 +1554,8 @@ impl PolyDatabase { { assert_eq!(self.env_ident, txn.txn.env.env_mut_ptr() as usize); - let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).ok_or(Error::Encoding)?; - let data_bytes: Cow<[u8]> = DC::bytes_encode(&data).ok_or(Error::Encoding)?; + let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).map_err(Error::Encoding)?; + let data_bytes: Cow<[u8]> = DC::bytes_encode(&data).map_err(Error::Encoding)?; let mut key_val = unsafe { crate::into_val(&key_bytes) }; let mut data_val = unsafe { crate::into_val(&data_bytes) }; @@ -1615,7 +1615,7 @@ impl PolyDatabase { { assert_eq!(self.env_ident, txn.txn.env.env_mut_ptr() as usize); - let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).ok_or(Error::Encoding)?; + let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).map_err(Error::Encoding)?; let mut key_val = unsafe { crate::into_val(&key_bytes) }; let result = unsafe { diff --git a/heed/src/iter/iter.rs b/heed/src/iter/iter.rs index c50db7fa..804e814f 100644 --- a/heed/src/iter/iter.rs +++ b/heed/src/iter/iter.rs @@ -56,8 +56,8 @@ where match result { Ok(Some((key, data))) => match (KC::bytes_decode(key), DC::bytes_decode(data)) { - (Some(key), Some(data)) => Some(Ok((key, data))), - (_, _) => Some(Err(Error::Decoding)), + (Ok(key), Ok(data)) => Some(Ok((key, data))), + (Err(e), _) | (_, Err(e)) => Some(Err(Error::Decoding(e))), }, Ok(None) => None, Err(e) => Some(Err(e)), @@ -79,8 +79,8 @@ where match result { Ok(Some((key, data))) => match (KC::bytes_decode(key), DC::bytes_decode(data)) { - (Some(key), Some(data)) => Some(Ok((key, data))), - (_, _) => Some(Err(Error::Decoding)), + (Ok(key), Ok(data)) => Some(Ok((key, data))), + (Err(e), _) | (_, Err(e)) => Some(Err(Error::Decoding(e))), }, Ok(None) => None, Err(e) => Some(Err(e)), @@ -148,8 +148,8 @@ impl<'txn, KC, DC> RwIter<'txn, KC, DC> { KC: BytesEncode<'a>, DC: BytesEncode<'a>, { - let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).ok_or(Error::Encoding)?; - let data_bytes: Cow<[u8]> = DC::bytes_encode(&data).ok_or(Error::Encoding)?; + let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).map_err(Error::Encoding)?; + let data_bytes: Cow<[u8]> = DC::bytes_encode(&data).map_err(Error::Encoding)?; self.cursor.put_current(&key_bytes, &data_bytes) } @@ -176,8 +176,8 @@ impl<'txn, KC, DC> RwIter<'txn, KC, DC> { KC: BytesEncode<'a>, DC: BytesEncode<'a>, { - let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).ok_or(Error::Encoding)?; - let data_bytes: Cow<[u8]> = DC::bytes_encode(&data).ok_or(Error::Encoding)?; + let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).map_err(Error::Encoding)?; + let data_bytes: Cow<[u8]> = DC::bytes_encode(&data).map_err(Error::Encoding)?; self.cursor.append(&key_bytes, &data_bytes) } @@ -223,8 +223,8 @@ where match result { Ok(Some((key, data))) => match (KC::bytes_decode(key), DC::bytes_decode(data)) { - (Some(key), Some(data)) => Some(Ok((key, data))), - (_, _) => Some(Err(Error::Decoding)), + (Ok(key), Ok(data)) => Some(Ok((key, data))), + (Err(e), _) | (_, Err(e)) => Some(Err(Error::Decoding(e))), }, Ok(None) => None, Err(e) => Some(Err(e)), @@ -246,8 +246,8 @@ where match result { Ok(Some((key, data))) => match (KC::bytes_decode(key), DC::bytes_decode(data)) { - (Some(key), Some(data)) => Some(Ok((key, data))), - (_, _) => Some(Err(Error::Decoding)), + (Ok(key), Ok(data)) => Some(Ok((key, data))), + (Err(e), _) | (_, Err(e)) => Some(Err(Error::Decoding(e))), }, Ok(None) => None, Err(e) => Some(Err(e)), @@ -308,8 +308,8 @@ where match result { Ok(Some((key, data))) => match (KC::bytes_decode(key), DC::bytes_decode(data)) { - (Some(key), Some(data)) => Some(Ok((key, data))), - (_, _) => Some(Err(Error::Decoding)), + (Ok(key), Ok(data)) => Some(Ok((key, data))), + (Err(e), _) | (_, Err(e)) => Some(Err(Error::Decoding(e))), }, Ok(None) => None, Err(e) => Some(Err(e)), @@ -331,8 +331,8 @@ where match result { Ok(Some((key, data))) => match (KC::bytes_decode(key), DC::bytes_decode(data)) { - (Some(key), Some(data)) => Some(Ok((key, data))), - (_, _) => Some(Err(Error::Decoding)), + (Ok(key), Ok(data)) => Some(Ok((key, data))), + (Err(e), _) | (_, Err(e)) => Some(Err(Error::Decoding(e))), }, Ok(None) => None, Err(e) => Some(Err(e)), @@ -400,8 +400,8 @@ impl<'txn, KC, DC> RwRevIter<'txn, KC, DC> { KC: BytesEncode<'a>, DC: BytesEncode<'a>, { - let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).ok_or(Error::Encoding)?; - let data_bytes: Cow<[u8]> = DC::bytes_encode(&data).ok_or(Error::Encoding)?; + let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).map_err(Error::Encoding)?; + let data_bytes: Cow<[u8]> = DC::bytes_encode(&data).map_err(Error::Encoding)?; self.cursor.put_current(&key_bytes, &data_bytes) } @@ -414,8 +414,8 @@ impl<'txn, KC, DC> RwRevIter<'txn, KC, DC> { KC: BytesEncode<'a>, DC: BytesEncode<'a>, { - let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).ok_or(Error::Encoding)?; - let data_bytes: Cow<[u8]> = DC::bytes_encode(&data).ok_or(Error::Encoding)?; + let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).map_err(Error::Encoding)?; + let data_bytes: Cow<[u8]> = DC::bytes_encode(&data).map_err(Error::Encoding)?; self.cursor.append(&key_bytes, &data_bytes) } @@ -461,8 +461,8 @@ where match result { Ok(Some((key, data))) => match (KC::bytes_decode(key), DC::bytes_decode(data)) { - (Some(key), Some(data)) => Some(Ok((key, data))), - (_, _) => Some(Err(Error::Decoding)), + (Ok(key), Ok(data)) => Some(Ok((key, data))), + (Err(e), _) | (_, Err(e)) => Some(Err(Error::Decoding(e))), }, Ok(None) => None, Err(e) => Some(Err(e)), @@ -484,8 +484,8 @@ where match result { Ok(Some((key, data))) => match (KC::bytes_decode(key), DC::bytes_decode(data)) { - (Some(key), Some(data)) => Some(Ok((key, data))), - (_, _) => Some(Err(Error::Decoding)), + (Ok(key), Ok(data)) => Some(Ok((key, data))), + (Err(e), _) | (_, Err(e)) => Some(Err(Error::Decoding(e))), }, Ok(None) => None, Err(e) => Some(Err(e)), diff --git a/heed/src/iter/prefix.rs b/heed/src/iter/prefix.rs index f8063ce1..9941613d 100644 --- a/heed/src/iter/prefix.rs +++ b/heed/src/iter/prefix.rs @@ -72,8 +72,8 @@ where Ok(Some((key, data))) => { if key.starts_with(&self.prefix) { match (KC::bytes_decode(key), DC::bytes_decode(data)) { - (Some(key), Some(data)) => Some(Ok((key, data))), - (_, _) => Some(Err(Error::Decoding)), + (Ok(key), Ok(data)) => Some(Ok((key, data))), + (Err(e), _) | (_, Err(e)) => Some(Err(Error::Decoding(e))), } } else { None @@ -101,8 +101,8 @@ where Ok(Some((key, data))) => { if key.starts_with(&self.prefix) { match (KC::bytes_decode(key), DC::bytes_decode(data)) { - (Some(key), Some(data)) => Some(Ok((key, data))), - (_, _) => Some(Err(Error::Decoding)), + (Ok(key), Ok(data)) => Some(Ok((key, data))), + (Err(e), _) | (_, Err(e)) => Some(Err(Error::Decoding(e))), } } else { None @@ -175,8 +175,8 @@ impl<'txn, KC, DC> RwPrefix<'txn, KC, DC> { KC: BytesEncode<'a>, DC: BytesEncode<'a>, { - let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).ok_or(Error::Encoding)?; - let data_bytes: Cow<[u8]> = DC::bytes_encode(&data).ok_or(Error::Encoding)?; + let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).map_err(Error::Encoding)?; + let data_bytes: Cow<[u8]> = DC::bytes_encode(&data).map_err(Error::Encoding)?; self.cursor.put_current(&key_bytes, &data_bytes) } @@ -203,8 +203,8 @@ impl<'txn, KC, DC> RwPrefix<'txn, KC, DC> { KC: BytesEncode<'a>, DC: BytesEncode<'a>, { - let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).ok_or(Error::Encoding)?; - let data_bytes: Cow<[u8]> = DC::bytes_encode(&data).ok_or(Error::Encoding)?; + let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).map_err(Error::Encoding)?; + let data_bytes: Cow<[u8]> = DC::bytes_encode(&data).map_err(Error::Encoding)?; self.cursor.append(&key_bytes, &data_bytes) } @@ -253,8 +253,8 @@ where Ok(Some((key, data))) => { if key.starts_with(&self.prefix) { match (KC::bytes_decode(key), DC::bytes_decode(data)) { - (Some(key), Some(data)) => Some(Ok((key, data))), - (_, _) => Some(Err(Error::Decoding)), + (Ok(key), Ok(data)) => Some(Ok((key, data))), + (Err(e), _) | (_, Err(e)) => Some(Err(Error::Decoding(e))), } } else { None @@ -282,8 +282,8 @@ where Ok(Some((key, data))) => { if key.starts_with(&self.prefix) { match (KC::bytes_decode(key), DC::bytes_decode(data)) { - (Some(key), Some(data)) => Some(Ok((key, data))), - (_, _) => Some(Err(Error::Decoding)), + (Ok(key), Ok(data)) => Some(Ok((key, data))), + (Err(e), _) | (_, Err(e)) => Some(Err(Error::Decoding(e))), } } else { None @@ -352,8 +352,8 @@ where Ok(Some((key, data))) => { if key.starts_with(&self.prefix) { match (KC::bytes_decode(key), DC::bytes_decode(data)) { - (Some(key), Some(data)) => Some(Ok((key, data))), - (_, _) => Some(Err(Error::Decoding)), + (Ok(key), Ok(data)) => Some(Ok((key, data))), + (Err(e), _) | (_, Err(e)) => Some(Err(Error::Decoding(e))), } } else { None @@ -383,8 +383,8 @@ where Ok(Some((key, data))) => { if key.starts_with(&self.prefix) { match (KC::bytes_decode(key), DC::bytes_decode(data)) { - (Some(key), Some(data)) => Some(Ok((key, data))), - (_, _) => Some(Err(Error::Decoding)), + (Ok(key), Ok(data)) => Some(Ok((key, data))), + (Err(e), _) | (_, Err(e)) => Some(Err(Error::Decoding(e))), } } else { None @@ -457,8 +457,8 @@ impl<'txn, KC, DC> RwRevPrefix<'txn, KC, DC> { KC: BytesEncode<'a>, DC: BytesEncode<'a>, { - let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).ok_or(Error::Encoding)?; - let data_bytes: Cow<[u8]> = DC::bytes_encode(&data).ok_or(Error::Encoding)?; + let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).map_err(Error::Encoding)?; + let data_bytes: Cow<[u8]> = DC::bytes_encode(&data).map_err(Error::Encoding)?; self.cursor.put_current(&key_bytes, &data_bytes) } @@ -485,8 +485,8 @@ impl<'txn, KC, DC> RwRevPrefix<'txn, KC, DC> { KC: BytesEncode<'a>, DC: BytesEncode<'a>, { - let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).ok_or(Error::Encoding)?; - let data_bytes: Cow<[u8]> = DC::bytes_encode(&data).ok_or(Error::Encoding)?; + let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).map_err(Error::Encoding)?; + let data_bytes: Cow<[u8]> = DC::bytes_encode(&data).map_err(Error::Encoding)?; self.cursor.append(&key_bytes, &data_bytes) } @@ -535,8 +535,8 @@ where Ok(Some((key, data))) => { if key.starts_with(&self.prefix) { match (KC::bytes_decode(key), DC::bytes_decode(data)) { - (Some(key), Some(data)) => Some(Ok((key, data))), - (_, _) => Some(Err(Error::Decoding)), + (Ok(key), Ok(data)) => Some(Ok((key, data))), + (Err(e), _) | (_, Err(e)) => Some(Err(Error::Decoding(e))), } } else { None @@ -566,8 +566,8 @@ where Ok(Some((key, data))) => { if key.starts_with(&self.prefix) { match (KC::bytes_decode(key), DC::bytes_decode(data)) { - (Some(key), Some(data)) => Some(Ok((key, data))), - (_, _) => Some(Err(Error::Decoding)), + (Ok(key), Ok(data)) => Some(Ok((key, data))), + (Err(e), _) | (_, Err(e)) => Some(Err(Error::Decoding(e))), } } else { None diff --git a/heed/src/iter/range.rs b/heed/src/iter/range.rs index ff3c1a9c..9e51825a 100644 --- a/heed/src/iter/range.rs +++ b/heed/src/iter/range.rs @@ -113,8 +113,8 @@ where if must_be_returned { match (KC::bytes_decode(key), DC::bytes_decode(data)) { - (Some(key), Some(data)) => Some(Ok((key, data))), - (_, _) => Some(Err(Error::Decoding)), + (Ok(key), Ok(data)) => Some(Ok((key, data))), + (Err(e), _) | (_, Err(e)) => Some(Err(Error::Decoding(e))), } } else { None @@ -148,8 +148,8 @@ where if must_be_returned { match (KC::bytes_decode(key), DC::bytes_decode(data)) { - (Some(key), Some(data)) => Some(Ok((key, data))), - (_, _) => Some(Err(Error::Decoding)), + (Ok(key), Ok(data)) => Some(Ok((key, data))), + (Err(e), _) | (_, Err(e)) => Some(Err(Error::Decoding(e))), } } else { None @@ -233,8 +233,8 @@ impl<'txn, KC, DC> RwRange<'txn, KC, DC> { KC: BytesEncode<'a>, DC: BytesEncode<'a>, { - let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).ok_or(Error::Encoding)?; - let data_bytes: Cow<[u8]> = DC::bytes_encode(&data).ok_or(Error::Encoding)?; + let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).map_err(Error::Encoding)?; + let data_bytes: Cow<[u8]> = DC::bytes_encode(&data).map_err(Error::Encoding)?; self.cursor.put_current(&key_bytes, &data_bytes) } @@ -261,8 +261,8 @@ impl<'txn, KC, DC> RwRange<'txn, KC, DC> { KC: BytesEncode<'a>, DC: BytesEncode<'a>, { - let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).ok_or(Error::Encoding)?; - let data_bytes: Cow<[u8]> = DC::bytes_encode(&data).ok_or(Error::Encoding)?; + let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).map_err(Error::Encoding)?; + let data_bytes: Cow<[u8]> = DC::bytes_encode(&data).map_err(Error::Encoding)?; self.cursor.append(&key_bytes, &data_bytes) } @@ -318,8 +318,8 @@ where if must_be_returned { match (KC::bytes_decode(key), DC::bytes_decode(data)) { - (Some(key), Some(data)) => Some(Ok((key, data))), - (_, _) => Some(Err(Error::Decoding)), + (Ok(key), Ok(data)) => Some(Ok((key, data))), + (Err(e), _) | (_, Err(e)) => Some(Err(Error::Decoding(e))), } } else { None @@ -353,8 +353,8 @@ where if must_be_returned { match (KC::bytes_decode(key), DC::bytes_decode(data)) { - (Some(key), Some(data)) => Some(Ok((key, data))), - (_, _) => Some(Err(Error::Decoding)), + (Ok(key), Ok(data)) => Some(Ok((key, data))), + (Err(e), _) | (_, Err(e)) => Some(Err(Error::Decoding(e))), } } else { None @@ -441,8 +441,8 @@ where if must_be_returned { match (KC::bytes_decode(key), DC::bytes_decode(data)) { - (Some(key), Some(data)) => Some(Ok((key, data))), - (_, _) => Some(Err(Error::Decoding)), + (Ok(key), Ok(data)) => Some(Ok((key, data))), + (Err(e), _) | (_, Err(e)) => Some(Err(Error::Decoding(e))), } } else { None @@ -478,8 +478,8 @@ where if must_be_returned { match (KC::bytes_decode(key), DC::bytes_decode(data)) { - (Some(key), Some(data)) => Some(Ok((key, data))), - (_, _) => Some(Err(Error::Decoding)), + (Ok(key), Ok(data)) => Some(Ok((key, data))), + (Err(e), _) | (_, Err(e)) => Some(Err(Error::Decoding(e))), } } else { None @@ -563,8 +563,8 @@ impl<'txn, KC, DC> RwRevRange<'txn, KC, DC> { KC: BytesEncode<'a>, DC: BytesEncode<'a>, { - let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).ok_or(Error::Encoding)?; - let data_bytes: Cow<[u8]> = DC::bytes_encode(&data).ok_or(Error::Encoding)?; + let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).map_err(Error::Encoding)?; + let data_bytes: Cow<[u8]> = DC::bytes_encode(&data).map_err(Error::Encoding)?; self.cursor.put_current(&key_bytes, &data_bytes) } @@ -591,8 +591,8 @@ impl<'txn, KC, DC> RwRevRange<'txn, KC, DC> { KC: BytesEncode<'a>, DC: BytesEncode<'a>, { - let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).ok_or(Error::Encoding)?; - let data_bytes: Cow<[u8]> = DC::bytes_encode(&data).ok_or(Error::Encoding)?; + let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).map_err(Error::Encoding)?; + let data_bytes: Cow<[u8]> = DC::bytes_encode(&data).map_err(Error::Encoding)?; self.cursor.append(&key_bytes, &data_bytes) } @@ -648,8 +648,8 @@ where if must_be_returned { match (KC::bytes_decode(key), DC::bytes_decode(data)) { - (Some(key), Some(data)) => Some(Ok((key, data))), - (_, _) => Some(Err(Error::Decoding)), + (Ok(key), Ok(data)) => Some(Ok((key, data))), + (Err(e), _) | (_, Err(e)) => Some(Err(Error::Decoding(e))), } } else { None @@ -685,8 +685,8 @@ where if must_be_returned { match (KC::bytes_decode(key), DC::bytes_decode(data)) { - (Some(key), Some(data)) => Some(Ok((key, data))), - (_, _) => Some(Err(Error::Decoding)), + (Ok(key), Ok(data)) => Some(Ok((key, data))), + (Err(e), _) | (_, Err(e)) => Some(Err(Error::Decoding(e))), } } else { None diff --git a/heed/src/lazy_decode.rs b/heed/src/lazy_decode.rs index b3b4b8e0..3ec3b64e 100644 --- a/heed/src/lazy_decode.rs +++ b/heed/src/lazy_decode.rs @@ -1,6 +1,6 @@ use std::marker; -use crate::{Error, Result}; +use heed_traits::BoxedError; /// Lazily decode the data bytes, it can be used to avoid CPU intensive decoding /// before making sure we really need to decode it (e.g. based on the key). @@ -10,8 +10,8 @@ pub struct LazyDecode(marker::PhantomData); impl<'a, C: 'static> heed_traits::BytesDecode<'a> for LazyDecode { type DItem = Lazy<'a, C>; - fn bytes_decode(bytes: &'a [u8]) -> Option { - Some(Lazy { data: bytes, _phantom: marker::PhantomData }) + fn bytes_decode(bytes: &'a [u8]) -> Result { + Ok(Lazy { data: bytes, _phantom: marker::PhantomData }) } } @@ -23,7 +23,7 @@ pub struct Lazy<'a, C> { } impl<'a, C: heed_traits::BytesDecode<'a>> Lazy<'a, C> { - pub fn decode(&self) -> Result { - C::bytes_decode(self.data).ok_or(Error::Decoding) + pub fn decode(&self) -> Result { + C::bytes_decode(self.data) } } diff --git a/heed/src/lib.rs b/heed/src/lib.rs index 514374ae..141207ab 100644 --- a/heed/src/lib.rs +++ b/heed/src/lib.rs @@ -71,7 +71,7 @@ pub use self::lazy_decode::{Lazy, LazyDecode}; pub use self::mdb::error::Error as MdbError; use self::mdb::ffi::{from_val, into_val}; pub use self::mdb::flags; -pub use self::traits::{BytesDecode, BytesEncode}; +pub use self::traits::{BoxedError, BytesDecode, BytesEncode}; pub use self::txn::{RoTxn, RwTxn}; /// An error that encapsulates all possible errors in this crate. @@ -79,8 +79,8 @@ pub use self::txn::{RoTxn, RwTxn}; pub enum Error { Io(io::Error), Mdb(MdbError), - Encoding, - Decoding, + Encoding(BoxedError), + Decoding(BoxedError), InvalidDatabaseTyping, DatabaseClosing, BadOpenOptions, @@ -91,8 +91,8 @@ impl fmt::Display for Error { match self { Error::Io(error) => write!(f, "{}", error), Error::Mdb(error) => write!(f, "{}", error), - Error::Encoding => f.write_str("error while encoding"), - Error::Decoding => f.write_str("error while decoding"), + Error::Encoding(error) => write!(f, "error while encoding: {}", error), + Error::Decoding(error) => write!(f, "error while decoding: {}", error), Error::InvalidDatabaseTyping => { f.write_str("database was previously opened with different types") } From 4673b11b8833d440b64cdf5bd335d8f8809f0bcc Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Wed, 14 Sep 2022 15:40:36 +0200 Subject: [PATCH 10/57] Reintroduce the tests in the sys crate --- .../tests/fixtures/testdb-32/data.mdb | Bin 0 -> 12288 bytes .../tests/fixtures/testdb-32/lock.mdb | Bin 0 -> 8192 bytes .../tests/fixtures/testdb/data.mdb | Bin 0 -> 180224 bytes .../tests/fixtures/testdb/lock.mdb | Bin 0 -> 8128 bytes lmdb-master3-sys/tests/lmdb.rs | 26 +++++ lmdb-master3-sys/tests/simple.rs | 91 ++++++++++++++++++ 6 files changed, 117 insertions(+) create mode 100644 lmdb-master3-sys/tests/fixtures/testdb-32/data.mdb create mode 100644 lmdb-master3-sys/tests/fixtures/testdb-32/lock.mdb create mode 100644 lmdb-master3-sys/tests/fixtures/testdb/data.mdb create mode 100644 lmdb-master3-sys/tests/fixtures/testdb/lock.mdb create mode 100644 lmdb-master3-sys/tests/lmdb.rs create mode 100644 lmdb-master3-sys/tests/simple.rs diff --git a/lmdb-master3-sys/tests/fixtures/testdb-32/data.mdb b/lmdb-master3-sys/tests/fixtures/testdb-32/data.mdb new file mode 100644 index 0000000000000000000000000000000000000000..81ba38959689a3c913c6b6ce8fc079118bbe9f1d GIT binary patch literal 12288 zcmeI$Jr05}6ae6A9Nh2-Jp!N(9!CdP5)Wt`IEPp82udN9u(}Y#*U%PvZunXxMR=&wTcz11@8E0v2HBLnY2oNAZfB*pk1PBlyK!Cu^0%M*2YyCg$ zkoQSr`hSpm&dvNp#}gnxfB*pk1PBlyK!5;&#S4se`ns#x+oCNNPXd4d0RjXF5FkK+ j009C72>gXW>~FaVWnIS9_tl{~p6YmQns_K!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk GPk{@K+Zplz literal 0 HcmV?d00001 diff --git a/lmdb-master3-sys/tests/fixtures/testdb/data.mdb b/lmdb-master3-sys/tests/fixtures/testdb/data.mdb new file mode 100644 index 0000000000000000000000000000000000000000..000798b6bd6b44a489ae2c6baa5671733126bd58 GIT binary patch literal 180224 zcmeI)Jx&`z7zW_+vNj7<3W`W+_6X*$pqd;7EJTY0qIFF{!Ch!5P{aXz0vEYLu8{qi zS;v+lB?=V54`6>Yvoo{I)4vnK=14=p>RtOLvK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBly zK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfWU_q$ocznIAsyaFpn>B9)}?f0t5&U zAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C7 z2oNAZfB*pk1PBlyu$2PS=F~-)gxkB>F|Cx@qJ zNA=b9bv?Vd38V1k;o$tKXxHteHRDv<_sahd7#ai!5FkK+009C72oNAZfB*pk1PBly zK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAh6W}f0zF+ zl2w^%-PJ$K|K~O9`Ts>+#zjoqDFg@*AV7cs0RjXF5FkK+009C72oNAZfB*pk1PBly zK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!Cs-2<&uwG~X9D&EL@L zMsx0eGQ6hX7FbTJJv&&f`7!4Gw zRzFmvCpp7kcl|O6)-6qXrkcm|{PD*4Ug}q=790J%PY6Zx zyNpZe|0JXkAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF z5FkK+009C72oNAZfB*pk1PBlyK!5;&_YmlB3dr{bM zAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C7 z2oNAZfB*pk1PBlyK;XX?sJs8Z3OT2r^ZUE$RFhQ4seVrL^SmOBZ?50pSQkRkyyHGT z$9wtzWTOxuK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U zAV7cs0RjXF5FkK+009C72oNAZfB=EIBd9{o_2)eQUZSZ|&H4U3e>3O*yL$qD0^7_& A8UO$Q literal 0 HcmV?d00001 diff --git a/lmdb-master3-sys/tests/fixtures/testdb/lock.mdb b/lmdb-master3-sys/tests/fixtures/testdb/lock.mdb new file mode 100644 index 0000000000000000000000000000000000000000..2ea5dccd82e97e524819f9f482b5d99af2408a3e GIT binary patch literal 8128 zcmeIuu@OK(5Cza95Gz9w`cQ;K87dG-R3SqpTF`(Q0_QR+c$@s)ot+Kdz8y;*nyLs- zWiiLPpVxCJ {{ + match $expr { + lmdb_master3_sys::MDB_SUCCESS => (), + err_code => assert!(false, "Failed with code {}", err_code), + } + }}; +} + +macro_rules! str { + ($expr:expr) => { + std::ffi::CString::new($expr).unwrap().as_ptr() + }; +} + +#[test] +#[cfg(target_pointer_width = "32")] +fn test_simple_32() { + test_simple("./tests/fixtures/testdb-32") +} + +#[test] +#[cfg(target_pointer_width = "64")] +fn test_simple_64() { + test_simple("./tests/fixtures/testdb") +} + +#[cfg(windows)] +fn get_file_fd(file: &File) -> std::os::windows::io::RawHandle { + use std::os::windows::io::AsRawHandle; + file.as_raw_handle() +} + +#[cfg(unix)] +fn get_file_fd(file: &File) -> std::os::unix::io::RawFd { + use std::os::unix::io::AsRawFd; + file.as_raw_fd() +} + +fn test_simple(env_path: &str) { + let mut env: *mut MDB_env = ptr::null_mut(); + let mut dbi: MDB_dbi = 0; + let mut key = MDB_val { + mv_size: 0, + mv_data: ptr::null_mut(), + }; + let mut data = MDB_val { + mv_size: 0, + mv_data: ptr::null_mut(), + }; + let mut txn: *mut MDB_txn = ptr::null_mut(); + let sval = str!("foo") as *mut c_void; + let dval = str!("bar") as *mut c_void; + + unsafe { + E!(mdb_env_create(&mut env)); + E!(mdb_env_set_maxdbs(env, 2)); + E!(mdb_env_open(env, str!(env_path), 0, 0664)); + + E!(mdb_txn_begin(env, ptr::null_mut(), 0, &mut txn)); + E!(mdb_dbi_open(txn, str!("subdb"), MDB_CREATE, &mut dbi)); + E!(mdb_txn_commit(txn)); + + key.mv_size = 3; + key.mv_data = sval; + data.mv_size = 3; + data.mv_data = dval; + + E!(mdb_txn_begin(env, ptr::null_mut(), 0, &mut txn)); + E!(mdb_put(txn, dbi, &mut key, &mut data, 0)); + E!(mdb_txn_commit(txn)); + } + + let file = File::create("./tests/fixtures/copytestdb.mdb").unwrap(); + + unsafe { + let fd = get_file_fd(&file); + E!(mdb_env_copyfd(env, fd)); + + mdb_dbi_close(env, dbi); + mdb_env_close(env); + } +} From eb39f0afa3d03e45be9935407cbb524b6e2c9d3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Thu, 15 Sep 2022 15:33:39 +0200 Subject: [PATCH 11/57] Upgrade all the heed subcrate dependencies --- heed-types/Cargo.toml | 12 ++++++------ heed/Cargo.toml | 18 +++++++++--------- lmdb-master3-sys/Cargo.toml | 8 ++++---- lmdb-master3-sys/bindgen.rs | 14 +++++++------- lmdb-master3-sys/src/bindings.rs | 8 ++++---- 5 files changed, 30 insertions(+), 30 deletions(-) diff --git a/heed-types/Cargo.toml b/heed-types/Cargo.toml index d207ad9b..8ea1b9ce 100644 --- a/heed-types/Cargo.toml +++ b/heed-types/Cargo.toml @@ -9,15 +9,15 @@ readme = "../README.md" edition = "2018" [dependencies] -bincode = { version = "1.2.1", optional = true } -bytemuck = { version = "1.5.0", features = ["extern_crate_alloc", "extern_crate_std"] } -byteorder = "1.4.2" +bincode = { version = "1.3.3", optional = true } +bytemuck = { version = "1.12.1", features = ["extern_crate_alloc", "extern_crate_std"] } +byteorder = "1.4.3" heed-traits = { version = "0.7.0", path = "../heed-traits" } -serde = { version = "1.0.117", optional = true } -serde_json = { version = "1.0.59", optional = true } +serde = { version = "1.0.144", optional = true } +serde_json = { version = "1.0.85", optional = true } [dev-dependencies] -rand = "0.8.2" +rand = "0.8.5" [features] default = ["serde-bincode", "serde-json"] diff --git a/heed/Cargo.toml b/heed/Cargo.toml index 4f592d7f..10ff6b01 100644 --- a/heed/Cargo.toml +++ b/heed/Cargo.toml @@ -11,24 +11,24 @@ readme = "../README.md" edition = "2018" [dependencies] -bytemuck = "1.5.0" -byteorder = { version = "1.3.4", default-features = false } +bytemuck = "1.12.1" +byteorder = { version = "1.4.3", default-features = false } heed-traits = { version = "0.7.0", path = "../heed-traits" } heed-types = { version = "0.7.2", path = "../heed-types" } -libc = "0.2.80" +libc = "0.2.132" lmdb-master3-sys = { path = "../lmdb-master3-sys" } -once_cell = "1.5.2" +once_cell = "1.14.0" page_size = "0.4.2" -serde = { version = "1.0.118", features = ["derive"], optional = true } -synchronoise = "1.0.0" +serde = { version = "1.0.144", features = ["derive"], optional = true } +synchronoise = "1.0.1" [dev-dependencies] -serde = { version = "1.0.118", features = ["derive"] } -bytemuck = { version = "1.5.0", features = ["derive"] } +serde = { version = "1.0.144", features = ["derive"] } +bytemuck = { version = "1.12.1", features = ["derive"] } tempfile = "3.3.0" [target.'cfg(windows)'.dependencies] -url = "2.2.0" +url = "2.3.1" [features] # The `serde` feature makes some types serializable, diff --git a/lmdb-master3-sys/Cargo.toml b/lmdb-master3-sys/Cargo.toml index ec0bfc61..a1674bce 100644 --- a/lmdb-master3-sys/Cargo.toml +++ b/lmdb-master3-sys/Cargo.toml @@ -23,12 +23,12 @@ build = "build.rs" name = "lmdb_master3_sys" [dependencies] -libc = "0.2" +libc = "0.2.132" [build-dependencies] -pkg-config = "0.3" -cc = "1.0" -bindgen = { version = "0.53.2", default-features = false, optional = true, features = ["runtime"] } +pkg-config = "0.3.25" +cc = "1.0.73" +bindgen = { version = "0.60.1", default-features = false, optional = true, features = ["runtime"] } [features] default = [] diff --git a/lmdb-master3-sys/bindgen.rs b/lmdb-master3-sys/bindgen.rs index f602fdd3..82f78a75 100644 --- a/lmdb-master3-sys/bindgen.rs +++ b/lmdb-master3-sys/bindgen.rs @@ -51,15 +51,15 @@ pub fn generate() { let bindings = bindgen::Builder::default() .header(lmdb.join("lmdb.h").to_string_lossy()) - .whitelist_var("^(MDB|mdb)_.*") - .whitelist_type("^(MDB|mdb)_.*") - .whitelist_function("^(MDB|mdb)_.*") + .allowlist_var("^(MDB|mdb)_.*") + .allowlist_type("^(MDB|mdb)_.*") + .allowlist_function("^(MDB|mdb)_.*") .size_t_is_usize(true) .ctypes_prefix("::libc") - .blacklist_item("mode_t") - .blacklist_item("mdb_mode_t") - .blacklist_item("mdb_filehandle_t") - .blacklist_item("^__.*") + .blocklist_item("mode_t") + .blocklist_item("mdb_mode_t") + .blocklist_item("mdb_filehandle_t") + .blocklist_item("^__.*") .parse_callbacks(Box::new(Callbacks {})) .layout_tests(false) .prepend_enum_name(false) diff --git a/lmdb-master3-sys/src/bindings.rs b/lmdb-master3-sys/src/bindings.rs index 8cb8318d..19d0eae5 100644 --- a/lmdb-master3-sys/src/bindings.rs +++ b/lmdb-master3-sys/src/bindings.rs @@ -1,12 +1,12 @@ -/* automatically generated by rust-bindgen */ +/* automatically generated by rust-bindgen 0.60.1 */ -pub const MDB_FMT_Z: &'static [u8; 2usize] = b"z\0"; +pub const MDB_FMT_Z: &[u8; 2usize] = b"z\0"; pub const MDB_RPAGE_CACHE: ::libc::c_uint = 1; pub const MDB_SIZE_MAX: u64 = 18446744073709551615; pub const MDB_VERSION_MAJOR: ::libc::c_uint = 0; pub const MDB_VERSION_MINOR: ::libc::c_uint = 9; pub const MDB_VERSION_PATCH: ::libc::c_uint = 90; -pub const MDB_VERSION_DATE: &'static [u8; 12usize] = b"May 1, 2017\0"; +pub const MDB_VERSION_DATE: &[u8; 12usize] = b"May 1, 2017\0"; pub const MDB_FIXEDMAP: ::libc::c_uint = 1; pub const MDB_ENCRYPT: ::libc::c_uint = 8192; pub const MDB_NOSUBDIR: ::libc::c_uint = 16384; @@ -207,7 +207,7 @@ pub const MDB_PREV_MULTIPLE: MDB_cursor_op = 18; #[doc = ""] #[doc = "\tThis is the set of all operations for retrieving data"] #[doc = "\tusing a cursor."] -pub type MDB_cursor_op = u32; +pub type MDB_cursor_op = ::libc::c_uint; #[doc = " @brief Statistics for a database in the environment"] #[repr(C)] pub struct MDB_stat { From 0b5cda0cf37856b431fda316023919bb0f41b073 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Wed, 14 Sep 2022 16:10:34 +0200 Subject: [PATCH 12/57] Ignore mdb databases --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 1919b36c..35efa2b0 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ heed/target **/*.rs.bk Cargo.lock -/*.mdb +*.mdb From a498ac4013ae4e908a1e54409f3a4aa81c623177 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Wed, 14 Sep 2022 16:27:09 +0200 Subject: [PATCH 13/57] Test to open a database with the MDB_WRITE_MAP flag --- heed/src/env.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/heed/src/env.rs b/heed/src/env.rs index 66b59acc..80da86cd 100644 --- a/heed/src/env.rs +++ b/heed/src/env.rs @@ -592,4 +592,15 @@ mod tests { .open(dir.path().join("babar.mdb")) .unwrap(); } + + #[test] + #[cfg(not(windows))] + fn open_database_with_writemap_flag() { + let dir = tempfile::tempdir().unwrap(); + let mut envbuilder = EnvOpenOptions::new(); + envbuilder.map_size(10 * 1024 * 1024); // 10MB + unsafe { envbuilder.flag(crate::flags::Flags::MdbWriteMap) }; + let env = envbuilder.open(&dir.path()).unwrap(); + let _db = env.create_database::(Some("my-super-db")).unwrap(); + } } From 51fd50f48f02c8a1d157378ffdfcd7c7e3dd81a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Thu, 15 Sep 2022 12:03:10 +0200 Subject: [PATCH 14/57] Change the create_database and open_database API --- heed/src/env.rs | 179 +++++++++++++++++++++++++++--------------------- 1 file changed, 101 insertions(+), 78 deletions(-) diff --git a/heed/src/env.rs b/heed/src/env.rs index 80da86cd..190f9807 100644 --- a/heed/src/env.rs +++ b/heed/src/env.rs @@ -280,109 +280,81 @@ impl Env { self.0.env } - pub fn open_database(&self, name: Option<&str>) -> Result>> + /// Opens a typed database that already exists in this environment. + /// + /// If the database was previously opened in this program run, types will be checked. + pub fn open_database( + &self, + rtxn: &RoTxn, + name: Option<&str>, + ) -> Result>> where KC: 'static, DC: 'static, { let types = (TypeId::of::(), TypeId::of::()); - Ok(self - .raw_open_database(name, Some(types))? - .map(|db| Database::new(self.env_mut_ptr() as _, db))) - } - - pub fn open_poly_database(&self, name: Option<&str>) -> Result> { - Ok(self - .raw_open_database(name, None)? - .map(|db| PolyDatabase::new(self.env_mut_ptr() as _, db))) + match self.raw_init_database(rtxn.txn, name, Some(types), false) { + Ok(dbi) => Ok(Some(Database::new(self.env_mut_ptr() as _, dbi))), + Err(Error::Mdb(e)) if e.not_found() => Ok(None), + Err(e) => Err(e), + } } - fn raw_open_database( + /// Opens an untyped database that already exists in this environment. + /// + /// If the database was previously opened as a typed one, an error will be returned. + pub fn open_poly_database( &self, + rtxn: &RoTxn, name: Option<&str>, - types: Option<(TypeId, TypeId)>, - ) -> Result> { - let rtxn = self.read_txn()?; - - let mut dbi = 0; - let name = name.map(|n| CString::new(n).unwrap()); - let name_ptr = match name { - Some(ref name) => name.as_bytes_with_nul().as_ptr() as *const _, - None => ptr::null(), - }; - - let mut lock = self.0.dbi_open_mutex.lock().unwrap(); - - let result = unsafe { mdb_result(ffi::mdb_dbi_open(rtxn.txn, name_ptr, 0, &mut dbi)) }; - - drop(name); - - match result { - Ok(()) => { - rtxn.commit()?; - - let old_types = lock.entry(dbi).or_insert(types); - - if *old_types == types { - Ok(Some(dbi)) - } else { - Err(Error::InvalidDatabaseTyping) - } - } - Err(e) if e.not_found() => Ok(None), - Err(e) => Err(e.into()), + ) -> Result> { + match self.raw_init_database(rtxn.txn, name, None, false) { + Ok(dbi) => Ok(Some(PolyDatabase::new(self.env_mut_ptr() as _, dbi))), + Err(Error::Mdb(e)) if e.not_found() => Ok(None), + Err(e) => Err(e), } } - pub fn create_database(&self, name: Option<&str>) -> Result> - where - KC: 'static, - DC: 'static, - { - let mut parent_wtxn = self.write_txn()?; - let db = self.create_database_with_txn(name, &mut parent_wtxn)?; - parent_wtxn.commit()?; - Ok(db) - } - - pub fn create_database_with_txn( + /// Creates a typed database that can already exist in this environment. + /// + /// If the database was previously opened in this program run, types will be checked. + pub fn create_database( &self, + wtxn: &mut RwTxn, name: Option<&str>, - parent_wtxn: &mut RwTxn, ) -> Result> where KC: 'static, DC: 'static, { let types = (TypeId::of::(), TypeId::of::()); - self.raw_create_database(name, Some(types), parent_wtxn) - .map(|db| Database::new(self.env_mut_ptr() as _, db)) - } - - pub fn create_poly_database(&self, name: Option<&str>) -> Result { - let mut parent_wtxn = self.write_txn()?; - let db = self.create_poly_database_with_txn(name, &mut parent_wtxn)?; - parent_wtxn.commit()?; - Ok(db) + match self.raw_init_database(wtxn.txn.txn, name, Some(types), true) { + Ok(dbi) => Ok(Database::new(self.env_mut_ptr() as _, dbi)), + Err(e) => Err(e), + } } - pub fn create_poly_database_with_txn( + /// Creates a typed database that can already exist in this environment. + /// + /// If the database was previously opened as a typed one, an error will be returned. + pub fn create_poly_database( &self, + wtxn: &mut RwTxn, name: Option<&str>, - parent_wtxn: &mut RwTxn, ) -> Result { - self.raw_create_database(name, None, parent_wtxn) - .map(|db| PolyDatabase::new(self.env_mut_ptr() as _, db)) + match self.raw_init_database(wtxn.txn.txn, name, None, true) { + Ok(dbi) => Ok(PolyDatabase::new(self.env_mut_ptr() as _, dbi)), + Err(e) => Err(e), + } } - fn raw_create_database( + fn raw_init_database( &self, + raw_txn: *mut ffi::MDB_txn, name: Option<&str>, types: Option<(TypeId, TypeId)>, - parent_wtxn: &mut RwTxn, + create: bool, ) -> Result { - let wtxn = self.nested_write_txn(parent_wtxn)?; - let mut dbi = 0; let name = name.map(|n| CString::new(n).unwrap()); let name_ptr = match name { @@ -391,19 +363,22 @@ impl Env { }; let mut lock = self.0.dbi_open_mutex.lock().unwrap(); - + // safety: The name cstring is cloned by LMDB, we can drop it after. + // If a read-only is used with the MDB_CREATE flag, LMDB will throw an error. let result = unsafe { - mdb_result(ffi::mdb_dbi_open(wtxn.txn.txn, name_ptr, ffi::MDB_CREATE, &mut dbi)) + mdb_result(ffi::mdb_dbi_open( + raw_txn, + name_ptr, + if create { ffi::MDB_CREATE } else { 0 }, + &mut dbi, + )) }; drop(name); match result { Ok(()) => { - wtxn.commit()?; - let old_types = lock.entry(dbi).or_insert(types); - if *old_types == types { Ok(dbi) } else { @@ -601,6 +576,54 @@ mod tests { envbuilder.map_size(10 * 1024 * 1024); // 10MB unsafe { envbuilder.flag(crate::flags::Flags::MdbWriteMap) }; let env = envbuilder.open(&dir.path()).unwrap(); - let _db = env.create_database::(Some("my-super-db")).unwrap(); + + let mut wtxn = env.write_txn().unwrap(); + let _db = env.create_database::(&mut wtxn, Some("my-super-db")).unwrap(); + wtxn.commit().unwrap(); + } + + #[test] + fn create_database_without_commit() { + let dir = tempfile::tempdir().unwrap(); + let env = EnvOpenOptions::new() + .map_size(10 * 1024 * 1024) // 10MB + .max_dbs(10) + .open(&dir.path()) + .unwrap(); + + let mut wtxn = env.write_txn().unwrap(); + let _db = env.create_database::(&mut wtxn, Some("my-super-db")).unwrap(); + wtxn.abort().unwrap(); + + let rtxn = env.read_txn().unwrap(); + let option = env.open_database::(&rtxn, Some("my-super-db")).unwrap(); + assert!(option.is_none()); + } + + #[test] + fn open_already_existing_database() { + let dir = tempfile::tempdir().unwrap(); + let env = EnvOpenOptions::new() + .map_size(10 * 1024 * 1024) // 10MB + .max_dbs(10) + .open(&dir.path()) + .unwrap(); + + // we first create a database + let mut wtxn = env.write_txn().unwrap(); + let _db = env.create_database::(&mut wtxn, Some("my-super-db")).unwrap(); + wtxn.commit().unwrap(); + + // Close the environement and reopen it, databases must not be loaded in memory. + env.prepare_for_closing().wait(); + let env = EnvOpenOptions::new() + .map_size(10 * 1024 * 1024) // 10MB + .max_dbs(10) + .open(&dir.path()) + .unwrap(); + + let rtxn = env.read_txn().unwrap(); + let option = env.open_database::(&rtxn, Some("my-super-db")).unwrap(); + assert!(option.is_some()); } } From 0104d5f0f89a29c116c4da9fbf3d6130e3844a2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Thu, 15 Sep 2022 12:30:29 +0200 Subject: [PATCH 15/57] Fix the tests and examples to match the new open/create_database API --- heed/examples/all-types-poly.rs | 28 ++++---- heed/examples/all-types.rs | 34 ++++----- heed/examples/clear-database.rs | 2 +- heed/examples/cursor-append.rs | 5 +- heed/examples/multi-env.rs | 7 +- heed/examples/nested.rs | 5 +- heed/src/db/polymorph.rs | 116 +++++++++++++++--------------- heed/src/db/uniform.rs | 120 ++++++++++++++++---------------- heed/src/env.rs | 9 ++- heed/src/iter/mod.rs | 33 +++++++-- heed/src/lib.rs | 4 +- 11 files changed, 192 insertions(+), 171 deletions(-) diff --git a/heed/examples/all-types-poly.rs b/heed/examples/all-types-poly.rs index dfa2b788..1be6618d 100644 --- a/heed/examples/all-types-poly.rs +++ b/heed/examples/all-types-poly.rs @@ -22,9 +22,9 @@ fn main() -> Result<(), Box> { // // like here we specify that the key will be an array of two i32 // and the data will be an str - let db = env.create_poly_database(Some("kikou"))?; - let mut wtxn = env.write_txn()?; + let db = env.create_poly_database(&mut wtxn, Some("kikou"))?; + db.put::, Str>(&mut wtxn, &[2, 3], "what's up?")?; let ret = db.get::, Str>(&wtxn, &[2, 3])?; @@ -32,9 +32,9 @@ fn main() -> Result<(), Box> { wtxn.commit()?; // here the key will be an str and the data will be a slice of u8 - let db = env.create_poly_database(Some("kiki"))?; - let mut wtxn = env.write_txn()?; + let db = env.create_poly_database(&mut wtxn, Some("kiki"))?; + db.put::(&mut wtxn, "hello", &[2, 3][..])?; let ret = db.get::(&wtxn, "hello")?; @@ -47,9 +47,8 @@ fn main() -> Result<(), Box> { string: &'a str, } - let db = env.create_poly_database(Some("serde"))?; - let mut wtxn = env.write_txn()?; + let db = env.create_poly_database(&mut wtxn, Some("serde"))?; let hello = Hello { string: "hi" }; db.put::>(&mut wtxn, "hello", &hello)?; @@ -71,9 +70,8 @@ fn main() -> Result<(), Box> { bytes: [u8; 12], } - let db = env.create_poly_database(Some("nocopy-struct"))?; - let mut wtxn = env.write_txn()?; + let db = env.create_poly_database(&mut wtxn, Some("nocopy-struct"))?; let zerobytes = ZeroBytes { bytes: [24; 12] }; db.put::>(&mut wtxn, "zero", &zerobytes)?; @@ -84,9 +82,9 @@ fn main() -> Result<(), Box> { wtxn.commit()?; // you can ignore the data - let db = env.create_poly_database(Some("ignored-data"))?; - let mut wtxn = env.write_txn()?; + let db = env.create_poly_database(&mut wtxn, Some("ignored-data"))?; + db.put::(&mut wtxn, "hello", &())?; let ret = db.get::(&wtxn, "hello")?; @@ -97,10 +95,11 @@ fn main() -> Result<(), Box> { println!("{:?}", ret); wtxn.commit()?; - // database opening and types are tested in a way + // database opening and types are tested in a safe way // // we try to open a database twice with the same types - let _db = env.create_poly_database(Some("ignored-data"))?; + let mut wtxn = env.write_txn()?; + let _db = env.create_poly_database(&mut wtxn, Some("ignored-data"))?; // and here we try to open it with other types // asserting that it correctly returns an error @@ -108,15 +107,14 @@ fn main() -> Result<(), Box> { // NOTE that those types are not saved upon runs and // therefore types cannot be checked upon different runs, // the first database opening fix the types for this run. - let result = env.create_database::, Unit>(Some("ignored-data")); + let result = env.create_database::, Unit>(&mut wtxn, Some("ignored-data")); assert!(result.is_err()); // you can iterate over keys in order type BEI64 = I64; - let db = env.create_poly_database(Some("big-endian-iter"))?; + let db = env.create_poly_database(&mut wtxn, Some("big-endian-iter"))?; - let mut wtxn = env.write_txn()?; db.put::, Unit>(&mut wtxn, &BEI64::new(0), &())?; db.put::, Unit>(&mut wtxn, &BEI64::new(68), &())?; db.put::, Unit>(&mut wtxn, &BEI64::new(35), &())?; diff --git a/heed/examples/all-types.rs b/heed/examples/all-types.rs index 0bc2b08f..a4895eaf 100644 --- a/heed/examples/all-types.rs +++ b/heed/examples/all-types.rs @@ -22,9 +22,9 @@ fn main() -> Result<(), Box> { // // like here we specify that the key will be an array of two i32 // and the data will be an str - let db: Database, Str> = env.create_database(Some("kikou"))?; - let mut wtxn = env.write_txn()?; + let db: Database, Str> = env.create_database(&mut wtxn, Some("kikou"))?; + let _ret = db.put(&mut wtxn, &[2, 3], "what's up?")?; let ret: Option<&str> = db.get(&wtxn, &[2, 3])?; @@ -32,9 +32,9 @@ fn main() -> Result<(), Box> { wtxn.commit()?; // here the key will be an str and the data will be a slice of u8 - let db: Database = env.create_database(Some("kiki"))?; - let mut wtxn = env.write_txn()?; + let db: Database = env.create_database(&mut wtxn, Some("kiki"))?; + let _ret = db.put(&mut wtxn, "hello", &[2, 3][..])?; let ret: Option<&[u8]> = db.get(&wtxn, "hello")?; @@ -47,9 +47,9 @@ fn main() -> Result<(), Box> { string: &'a str, } - let db: Database> = env.create_database(Some("serde-bincode"))?; - let mut wtxn = env.write_txn()?; + let db: Database> = + env.create_database(&mut wtxn, Some("serde-bincode"))?; let hello = Hello { string: "hi" }; db.put(&mut wtxn, "hello", &hello)?; @@ -59,9 +59,8 @@ fn main() -> Result<(), Box> { wtxn.commit()?; - let db: Database> = env.create_database(Some("serde-json"))?; - let mut wtxn = env.write_txn()?; + let db: Database> = env.create_database(&mut wtxn, Some("serde-json"))?; let hello = Hello { string: "hi" }; db.put(&mut wtxn, "hello", &hello)?; @@ -78,9 +77,9 @@ fn main() -> Result<(), Box> { bytes: [u8; 12], } - let db: Database> = env.create_database(Some("simple-struct"))?; - let mut wtxn = env.write_txn()?; + let db: Database> = + env.create_database(&mut wtxn, Some("simple-struct"))?; let zerobytes = ZeroBytes { bytes: [24; 12] }; db.put(&mut wtxn, "zero", &zerobytes)?; @@ -91,9 +90,9 @@ fn main() -> Result<(), Box> { wtxn.commit()?; // you can ignore the data - let db: Database = env.create_database(Some("ignored-data"))?; - let mut wtxn = env.write_txn()?; + let db: Database = env.create_database(&mut wtxn, Some("ignored-data"))?; + let _ret = db.put(&mut wtxn, "hello", &())?; let ret: Option<()> = db.get(&wtxn, "hello")?; @@ -104,10 +103,11 @@ fn main() -> Result<(), Box> { println!("{:?}", ret); wtxn.commit()?; - // database opening and types are tested in a way + // database opening and types are tested in a safe way // // we try to open a database twice with the same types - let _db: Database = env.create_database(Some("ignored-data"))?; + let mut wtxn = env.write_txn()?; + let _db: Database = env.create_database(&mut wtxn, Some("ignored-data"))?; // and here we try to open it with other types // asserting that it correctly returns an error @@ -115,15 +115,15 @@ fn main() -> Result<(), Box> { // NOTE that those types are not saved upon runs and // therefore types cannot be checked upon different runs, // the first database opening fix the types for this run. - let result = env.create_database::>(Some("ignored-data")); + let result = env.create_database::>(&mut wtxn, Some("ignored-data")); assert!(result.is_err()); // you can iterate over keys in order type BEI64 = I64; - let db: Database, Unit> = env.create_database(Some("big-endian-iter"))?; + let db: Database, Unit> = + env.create_database(&mut wtxn, Some("big-endian-iter"))?; - let mut wtxn = env.write_txn()?; let _ret = db.put(&mut wtxn, &BEI64::new(0), &())?; let _ret = db.put(&mut wtxn, &BEI64::new(68), &())?; let _ret = db.put(&mut wtxn, &BEI64::new(35), &())?; diff --git a/heed/examples/clear-database.rs b/heed/examples/clear-database.rs index e87aed38..bc3cea75 100644 --- a/heed/examples/clear-database.rs +++ b/heed/examples/clear-database.rs @@ -18,8 +18,8 @@ fn main() -> Result<(), Box> { .max_dbs(3) .open(env_path)?; - let db: Database = env.create_database(Some("first"))?; let mut wtxn = env.write_txn()?; + let db: Database = env.create_database(&mut wtxn, Some("first"))?; // We fill the db database with entries. db.put(&mut wtxn, "I am here", "to test things")?; diff --git a/heed/examples/cursor-append.rs b/heed/examples/cursor-append.rs index 6f487c41..596761f3 100644 --- a/heed/examples/cursor-append.rs +++ b/heed/examples/cursor-append.rs @@ -18,10 +18,9 @@ fn main() -> Result<(), Box> { .max_dbs(3) .open(env_path)?; - let first: Database = env.create_database(Some("first"))?; - let second: Database = env.create_database(Some("second"))?; - let mut wtxn = env.write_txn()?; + let first: Database = env.create_database(&mut wtxn, Some("first"))?; + let second: Database = env.create_database(&mut wtxn, Some("second"))?; // We fill the first database with entries. first.put(&mut wtxn, "I am here", "to test things")?; diff --git a/heed/examples/multi-env.rs b/heed/examples/multi-env.rs index 49895d63..50331ecb 100644 --- a/heed/examples/multi-env.rs +++ b/heed/examples/multi-env.rs @@ -21,11 +21,12 @@ fn main() -> Result<(), Box> { .max_dbs(3000) .open(env2_path)?; - let db1: Database = env1.create_database(Some("hello"))?; - let db2: Database, OwnedType> = env2.create_database(Some("hello"))?; + let mut wtxn = env1.write_txn()?; + let db1: Database = env1.create_database(&mut wtxn, Some("hello"))?; + let db2: Database, OwnedType> = + env2.create_database(&mut wtxn, Some("hello"))?; // clear db - let mut wtxn = env1.write_txn()?; db1.clear(&mut wtxn)?; wtxn.commit()?; diff --git a/heed/examples/nested.rs b/heed/examples/nested.rs index fea6f654..0bbbb6a2 100644 --- a/heed/examples/nested.rs +++ b/heed/examples/nested.rs @@ -16,17 +16,16 @@ fn main() -> Result<(), Box> { .open(path)?; // here the key will be an str and the data will be a slice of u8 - let db: Database = env.create_database(None)?; + let mut wtxn = env.write_txn()?; + let db: Database = env.create_database(&mut wtxn, None)?; // clear db - let mut wtxn = env.write_txn()?; db.clear(&mut wtxn)?; wtxn.commit()?; // ----- let mut wtxn = env.write_txn()?; - let mut nwtxn = env.nested_write_txn(&mut wtxn)?; db.put(&mut nwtxn, "what", &[4, 5][..])?; diff --git a/heed/src/db/polymorph.rs b/heed/src/db/polymorph.rs index 2453a665..149a70d6 100644 --- a/heed/src/db/polymorph.rs +++ b/heed/src/db/polymorph.rs @@ -31,9 +31,9 @@ use crate::*; /// # .open(dir.path())?; /// type BEI64 = I64; /// -/// let db: PolyDatabase = env.create_poly_database(Some("big-endian-iter"))?; -/// /// let mut wtxn = env.write_txn()?; +/// let db: PolyDatabase = env.create_poly_database(&mut wtxn, Some("big-endian-iter"))?; +/// /// # db.clear(&mut wtxn)?; /// db.put::, Unit>(&mut wtxn, &BEI64::new(0), &())?; /// db.put::, Str>(&mut wtxn, &BEI64::new(35), "thirty five")?; @@ -74,9 +74,9 @@ use crate::*; /// # .open(dir.path())?; /// type BEI64 = I64; /// -/// let db: PolyDatabase = env.create_poly_database(Some("big-endian-iter"))?; -/// /// let mut wtxn = env.write_txn()?; +/// let db: PolyDatabase = env.create_poly_database(&mut wtxn, Some("big-endian-iter"))?; +/// /// # db.clear(&mut wtxn)?; /// db.put::, Unit>(&mut wtxn, &BEI64::new(0), &())?; /// db.put::, Str>(&mut wtxn, &BEI64::new(35), "thirty five")?; @@ -130,9 +130,9 @@ impl PolyDatabase { /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) /// # .open(dir.path())?; - /// let db = env.create_poly_database(Some("get-poly-i32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db = env.create_poly_database(&mut wtxn, Some("get-poly-i32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put::>(&mut wtxn, "i-am-forty-two", &42)?; /// db.put::>(&mut wtxn, "i-am-twenty-seven", &27)?; @@ -200,9 +200,9 @@ impl PolyDatabase { /// # .open(dir.path())?; /// type BEU32 = U32; /// - /// let db = env.create_poly_database(Some("get-lt-u32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db = env.create_poly_database(&mut wtxn, Some("get-lt-u32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put::, Unit>(&mut wtxn, &BEU32::new(27), &())?; /// db.put::, Unit>(&mut wtxn, &BEU32::new(42), &())?; @@ -268,9 +268,9 @@ impl PolyDatabase { /// # .open(dir.path())?; /// type BEU32 = U32; /// - /// let db = env.create_poly_database(Some("get-lte-u32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db = env.create_poly_database(&mut wtxn, Some("get-lte-u32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put::, Unit>(&mut wtxn, &BEU32::new(27), &())?; /// db.put::, Unit>(&mut wtxn, &BEU32::new(42), &())?; @@ -340,9 +340,9 @@ impl PolyDatabase { /// # .open(dir.path())?; /// type BEU32 = U32; /// - /// let db = env.create_poly_database(Some("get-lt-u32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db = env.create_poly_database(&mut wtxn, Some("get-lt-u32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put::, Unit>(&mut wtxn, &BEU32::new(27), &())?; /// db.put::, Unit>(&mut wtxn, &BEU32::new(42), &())?; @@ -411,9 +411,9 @@ impl PolyDatabase { /// # .open(dir.path())?; /// type BEU32 = U32; /// - /// let db = env.create_poly_database(Some("get-lt-u32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db = env.create_poly_database(&mut wtxn, Some("get-lt-u32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put::, Unit>(&mut wtxn, &BEU32::new(27), &())?; /// db.put::, Unit>(&mut wtxn, &BEU32::new(42), &())?; @@ -476,9 +476,9 @@ impl PolyDatabase { /// # .open(dir.path())?; /// type BEI32 = I32; /// - /// let db = env.create_poly_database(Some("first-poly-i32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db = env.create_poly_database(&mut wtxn, Some("first-poly-i32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put::, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; /// db.put::, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; @@ -529,9 +529,9 @@ impl PolyDatabase { /// # .open(dir.path())?; /// type BEI32 = I32; /// - /// let db = env.create_poly_database(Some("last-i32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db = env.create_poly_database(&mut wtxn, Some("last-i32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put::, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; /// db.put::, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; @@ -578,9 +578,9 @@ impl PolyDatabase { /// # .open(dir.path())?; /// type BEI32 = I32; /// - /// let db = env.create_poly_database(Some("iter-i32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db = env.create_poly_database(&mut wtxn, Some("iter-i32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put::, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; /// db.put::, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; @@ -632,9 +632,9 @@ impl PolyDatabase { /// # .open(dir.path())?; /// type BEI32 = I32; /// - /// let db = env.create_poly_database(Some("iter-i32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db = env.create_poly_database(&mut wtxn, Some("iter-i32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put::, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; /// db.put::, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; @@ -680,9 +680,9 @@ impl PolyDatabase { /// # .open(dir.path())?; /// type BEI32 = I32; /// - /// let db = env.create_poly_database(Some("iter-i32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db = env.create_poly_database(&mut wtxn, Some("iter-i32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put::, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; /// db.put::, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; @@ -722,9 +722,9 @@ impl PolyDatabase { /// # .open(dir.path())?; /// type BEI32 = I32; /// - /// let db = env.create_poly_database(Some("iter-i32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db = env.create_poly_database(&mut wtxn, Some("iter-i32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put::, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; /// db.put::, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; @@ -777,9 +777,9 @@ impl PolyDatabase { /// # .open(dir.path())?; /// type BEI32 = I32; /// - /// let db = env.create_poly_database(Some("iter-i32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db = env.create_poly_database(&mut wtxn, Some("iter-i32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put::, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; /// db.put::, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; @@ -820,9 +820,9 @@ impl PolyDatabase { /// # .open(dir.path())?; /// type BEI32 = I32; /// - /// let db = env.create_poly_database(Some("iter-i32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db = env.create_poly_database(&mut wtxn, Some("iter-i32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put::, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; /// db.put::, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; @@ -880,9 +880,9 @@ impl PolyDatabase { /// # .open(dir.path())?; /// type BEI32 = I32; /// - /// let db = env.create_poly_database(Some("iter-i32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db = env.create_poly_database(&mut wtxn, Some("iter-i32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put::, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; /// db.put::, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; @@ -958,9 +958,9 @@ impl PolyDatabase { /// # .open(dir.path())?; /// type BEI32 = I32; /// - /// let db = env.create_poly_database(Some("iter-i32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db = env.create_poly_database(&mut wtxn, Some("iter-i32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put::, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; /// db.put::, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; @@ -1049,9 +1049,9 @@ impl PolyDatabase { /// # .open(dir.path())?; /// type BEI32 = I32; /// - /// let db = env.create_poly_database(Some("iter-i32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db = env.create_poly_database(&mut wtxn, Some("iter-i32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put::, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; /// db.put::, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; @@ -1127,9 +1127,9 @@ impl PolyDatabase { /// # .open(dir.path())?; /// type BEI32 = I32; /// - /// let db = env.create_poly_database(Some("iter-i32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db = env.create_poly_database(&mut wtxn, Some("iter-i32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put::, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; /// db.put::, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; @@ -1218,9 +1218,9 @@ impl PolyDatabase { /// # .open(dir.path())?; /// type BEI32 = I32; /// - /// let db = env.create_poly_database(Some("iter-i32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db = env.create_poly_database(&mut wtxn, Some("iter-i32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put::>(&mut wtxn, "i-am-twenty-eight", &BEI32::new(28))?; /// db.put::>(&mut wtxn, "i-am-twenty-seven", &BEI32::new(27))?; @@ -1274,9 +1274,9 @@ impl PolyDatabase { /// # .open(dir.path())?; /// type BEI32 = I32; /// - /// let db = env.create_poly_database(Some("iter-i32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db = env.create_poly_database(&mut wtxn, Some("iter-i32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put::>(&mut wtxn, "i-am-twenty-eight", &BEI32::new(28))?; /// db.put::>(&mut wtxn, "i-am-twenty-seven", &BEI32::new(27))?; @@ -1343,9 +1343,9 @@ impl PolyDatabase { /// # .open(dir.path())?; /// type BEI32 = I32; /// - /// let db = env.create_poly_database(Some("iter-i32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db = env.create_poly_database(&mut wtxn, Some("iter-i32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put::>(&mut wtxn, "i-am-twenty-eight", &BEI32::new(28))?; /// db.put::>(&mut wtxn, "i-am-twenty-seven", &BEI32::new(27))?; @@ -1399,9 +1399,9 @@ impl PolyDatabase { /// # .open(dir.path())?; /// type BEI32 = I32; /// - /// let db = env.create_poly_database(Some("iter-i32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db = env.create_poly_database(&mut wtxn, Some("iter-i32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put::>(&mut wtxn, "i-am-twenty-eight", &BEI32::new(28))?; /// db.put::>(&mut wtxn, "i-am-twenty-seven", &BEI32::new(27))?; @@ -1465,9 +1465,9 @@ impl PolyDatabase { /// # .open(dir.path())?; /// type BEI32 = I32; /// - /// let db = env.create_poly_database(Some("iter-i32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db = env.create_poly_database(&mut wtxn, Some("iter-i32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put::, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; /// db.put::, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; @@ -1527,9 +1527,9 @@ impl PolyDatabase { /// # .open(dir.path())?; /// type BEI32 = I32; /// - /// let db = env.create_poly_database(Some("append-i32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db = env.create_poly_database(&mut wtxn, Some("append-i32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put::, Str>(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; /// db.put::, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; @@ -1588,9 +1588,9 @@ impl PolyDatabase { /// # .open(dir.path())?; /// type BEI32 = I32; /// - /// let db = env.create_poly_database(Some("iter-i32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db = env.create_poly_database(&mut wtxn, Some("iter-i32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put::, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; /// db.put::, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; @@ -1654,9 +1654,9 @@ impl PolyDatabase { /// # .open(dir.path())?; /// type BEI32 = I32; /// - /// let db = env.create_poly_database(Some("iter-i32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db = env.create_poly_database(&mut wtxn, Some("iter-i32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put::, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; /// db.put::, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; @@ -1720,9 +1720,9 @@ impl PolyDatabase { /// # .open(dir.path())?; /// type BEI32 = I32; /// - /// let db = env.create_poly_database(Some("iter-i32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db = env.create_poly_database(&mut wtxn, Some("iter-i32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put::, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; /// db.put::, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; @@ -1769,9 +1769,9 @@ impl PolyDatabase { /// # .open(dir.path())?; /// type BEI32 = I32; /// - /// let db = env.create_poly_database(Some("iter-i32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db = env.create_poly_database(&mut wtxn, Some("iter-i32"))?; + /// /// # db.clear(&mut wtxn)?; /// // We remap the types for ease of use. /// let db = db.as_uniform::, Str>(); diff --git a/heed/src/db/uniform.rs b/heed/src/db/uniform.rs index fd018ee5..fe9790e7 100644 --- a/heed/src/db/uniform.rs +++ b/heed/src/db/uniform.rs @@ -28,9 +28,9 @@ use crate::*; /// # .open(dir.path())?; /// type BEI64 = I64; /// -/// let db: Database, Unit> = env.create_database(Some("big-endian-iter"))?; -/// /// let mut wtxn = env.write_txn()?; +/// let db: Database, Unit> = env.create_database(&mut wtxn, Some("big-endian-iter"))?; +/// /// # db.clear(&mut wtxn)?; /// db.put(&mut wtxn, &BEI64::new(68), &())?; /// db.put(&mut wtxn, &BEI64::new(35), &())?; @@ -75,9 +75,9 @@ use crate::*; /// # .open(dir.path())?; /// type BEI64 = I64; /// -/// let db: Database, Unit> = env.create_database(Some("big-endian-iter"))?; -/// /// let mut wtxn = env.write_txn()?; +/// let db: Database, Unit> = env.create_database(&mut wtxn, Some("big-endian-iter"))?; +/// /// # db.clear(&mut wtxn)?; /// db.put(&mut wtxn, &BEI64::new(0), &())?; /// db.put(&mut wtxn, &BEI64::new(68), &())?; @@ -141,9 +141,9 @@ impl Database { /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) /// # .open(dir.path())?; - /// let db: Database> = env.create_database(Some("get-i32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db: Database> = env.create_database(&mut wtxn, Some("get-i32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put(&mut wtxn, "i-am-forty-two", &42)?; /// db.put(&mut wtxn, "i-am-twenty-seven", &27)?; @@ -188,9 +188,9 @@ impl Database { /// # .open(dir.path())?; /// type BEU32 = U32; /// - /// let db = env.create_database::, Unit>(Some("get-lt-u32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db = env.create_database::, Unit>(&mut wtxn, Some("get-lt-u32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put(&mut wtxn, &BEU32::new(27), &())?; /// db.put(&mut wtxn, &BEU32::new(42), &())?; @@ -243,9 +243,9 @@ impl Database { /// # .open(dir.path())?; /// type BEU32 = U32; /// - /// let db = env.create_database::, Unit>(Some("get-lt-u32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db = env.create_database::, Unit>(&mut wtxn, Some("get-lt-u32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put(&mut wtxn, &BEU32::new(27), &())?; /// db.put(&mut wtxn, &BEU32::new(42), &())?; @@ -298,9 +298,9 @@ impl Database { /// # .open(dir.path())?; /// type BEU32 = U32; /// - /// let db = env.create_database::, Unit>(Some("get-lt-u32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db = env.create_database::, Unit>(&mut wtxn, Some("get-lt-u32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put(&mut wtxn, &BEU32::new(27), &())?; /// db.put(&mut wtxn, &BEU32::new(42), &())?; @@ -353,9 +353,9 @@ impl Database { /// # .open(dir.path())?; /// type BEU32 = U32; /// - /// let db = env.create_database::, Unit>(Some("get-lt-u32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db = env.create_database::, Unit>(&mut wtxn, Some("get-lt-u32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put(&mut wtxn, &BEU32::new(27), &())?; /// db.put(&mut wtxn, &BEU32::new(42), &())?; @@ -407,9 +407,9 @@ impl Database { /// # .open(dir.path())?; /// type BEI32 = I32; /// - /// let db: Database, Str> = env.create_database(Some("first-i32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db: Database, Str> = env.create_database(&mut wtxn, Some("first-i32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; /// db.put(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; @@ -450,9 +450,9 @@ impl Database { /// # .open(dir.path())?; /// type BEI32 = I32; /// - /// let db: Database, Str> = env.create_database(Some("last-i32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db: Database, Str> = env.create_database(&mut wtxn, Some("last-i32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; /// db.put(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; @@ -489,9 +489,9 @@ impl Database { /// # .open(dir.path())?; /// type BEI32 = I32; /// - /// let db: Database, Str> = env.create_database(Some("iter-i32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db: Database, Str> = env.create_database(&mut wtxn, Some("iter-i32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; /// db.put(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; @@ -531,9 +531,9 @@ impl Database { /// # .open(dir.path())?; /// type BEI32 = I32; /// - /// let db: Database, Str> = env.create_database(Some("iter-i32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db: Database, Str> = env.create_database(&mut wtxn, Some("iter-i32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; /// db.put(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; @@ -573,9 +573,9 @@ impl Database { /// # .open(dir.path())?; /// type BEI32 = I32; /// - /// let db: Database, Str> = env.create_database(Some("iter-i32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db: Database, Str> = env.create_database(&mut wtxn, Some("iter-i32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; /// db.put(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; @@ -613,9 +613,9 @@ impl Database { /// # .open(dir.path())?; /// type BEI32 = I32; /// - /// let db: Database, Str> = env.create_database(Some("iter-i32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db: Database, Str> = env.create_database(&mut wtxn, Some("iter-i32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; /// db.put(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; @@ -666,9 +666,9 @@ impl Database { /// # .open(dir.path())?; /// type BEI32 = I32; /// - /// let db: Database, Str> = env.create_database(Some("iter-i32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db: Database, Str> = env.create_database(&mut wtxn, Some("iter-i32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; /// db.put(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; @@ -707,9 +707,9 @@ impl Database { /// # .open(dir.path())?; /// type BEI32 = I32; /// - /// let db: Database, Str> = env.create_database(Some("iter-i32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db: Database, Str> = env.create_database(&mut wtxn, Some("iter-i32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; /// db.put(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; @@ -762,9 +762,9 @@ impl Database { /// # .open(dir.path())?; /// type BEI32 = I32; /// - /// let db: Database, Str> = env.create_database(Some("iter-i32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db: Database, Str> = env.create_database(&mut wtxn, Some("iter-i32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; /// db.put(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; @@ -814,9 +814,9 @@ impl Database { /// # .open(dir.path())?; /// type BEI32 = I32; /// - /// let db: Database, Str> = env.create_database(Some("iter-i32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db: Database, Str> = env.create_database(&mut wtxn, Some("iter-i32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; /// db.put(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; @@ -879,9 +879,9 @@ impl Database { /// # .open(dir.path())?; /// type BEI32 = I32; /// - /// let db: Database, Str> = env.create_database(Some("iter-i32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db: Database, Str> = env.create_database(&mut wtxn, Some("iter-i32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; /// db.put(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; @@ -931,9 +931,9 @@ impl Database { /// # .open(dir.path())?; /// type BEI32 = I32; /// - /// let db: Database, Str> = env.create_database(Some("iter-i32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db: Database, Str> = env.create_database(&mut wtxn, Some("iter-i32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; /// db.put(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; @@ -996,9 +996,9 @@ impl Database { /// # .open(dir.path())?; /// type BEI32 = I32; /// - /// let db: Database> = env.create_database(Some("iter-i32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db: Database> = env.create_database(&mut wtxn, Some("iter-i32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put(&mut wtxn, "i-am-twenty-eight", &BEI32::new(28))?; /// db.put(&mut wtxn, "i-am-twenty-seven", &BEI32::new(27))?; @@ -1048,9 +1048,9 @@ impl Database { /// # .open(dir.path())?; /// type BEI32 = I32; /// - /// let db: Database> = env.create_database(Some("iter-i32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db: Database> = env.create_database(&mut wtxn, Some("iter-i32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put(&mut wtxn, "i-am-twenty-eight", &BEI32::new(28))?; /// db.put(&mut wtxn, "i-am-twenty-seven", &BEI32::new(27))?; @@ -1113,9 +1113,9 @@ impl Database { /// # .open(dir.path())?; /// type BEI32 = I32; /// - /// let db: Database> = env.create_database(Some("iter-i32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db: Database> = env.create_database(&mut wtxn, Some("iter-i32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put(&mut wtxn, "i-am-twenty-eight", &BEI32::new(28))?; /// db.put(&mut wtxn, "i-am-twenty-seven", &BEI32::new(27))?; @@ -1165,9 +1165,9 @@ impl Database { /// # .open(dir.path())?; /// type BEI32 = I32; /// - /// let db: Database> = env.create_database(Some("iter-i32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db: Database> = env.create_database(&mut wtxn, Some("iter-i32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put(&mut wtxn, "i-am-twenty-eight", &BEI32::new(28))?; /// db.put(&mut wtxn, "i-am-twenty-seven", &BEI32::new(27))?; @@ -1227,9 +1227,9 @@ impl Database { /// # .open(dir.path())?; /// type BEI32 = I32; /// - /// let db: Database, Str> = env.create_database(Some("iter-i32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db: Database, Str> = env.create_database(&mut wtxn, Some("iter-i32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; /// db.put(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; @@ -1271,9 +1271,9 @@ impl Database { /// # .open(dir.path())?; /// type BEI32 = I32; /// - /// let db: Database, Str> = env.create_database(Some("iter-i32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db: Database, Str> = env.create_database(&mut wtxn, Some("iter-i32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; /// db.put(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; @@ -1314,9 +1314,9 @@ impl Database { /// # .open(dir.path())?; /// type BEI32 = I32; /// - /// let db: Database, Str> = env.create_database(Some("iter-i32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db: Database, Str> = env.create_database(&mut wtxn, Some("iter-i32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; /// db.put(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; @@ -1367,9 +1367,9 @@ impl Database { /// # .open(dir.path())?; /// type BEI32 = I32; /// - /// let db: Database, Str> = env.create_database(Some("iter-i32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db: Database, Str> = env.create_database(&mut wtxn, Some("iter-i32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; /// db.put(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; @@ -1421,9 +1421,9 @@ impl Database { /// # .open(dir.path())?; /// type BEI32 = I32; /// - /// let db: Database, Str> = env.create_database(Some("iter-i32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db: Database, Str> = env.create_database(&mut wtxn, Some("iter-i32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; /// db.put(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; @@ -1468,9 +1468,9 @@ impl Database { /// # .open(dir.path())?; /// type BEI32 = I32; /// - /// let db: Database = env.create_database(Some("iter-i32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db: Database = env.create_database(&mut wtxn, Some("iter-i32"))?; + /// /// # db.clear(&mut wtxn)?; /// // We remap the types for ease of use. /// let db = db.remap_types::, Str>(); @@ -1532,9 +1532,9 @@ impl Database { /// # .open(dir.path())?; /// type BEI32 = I32; /// - /// let db: Database, Str> = env.create_database(Some("iter-i32"))?; - /// /// let mut wtxn = env.write_txn()?; + /// let db: Database, Str> = env.create_database(&mut wtxn, Some("iter-i32"))?; + /// /// # db.clear(&mut wtxn)?; /// db.put(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; /// db.put(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; diff --git a/heed/src/env.rs b/heed/src/env.rs index 190f9807..ef7efc46 100644 --- a/heed/src/env.rs +++ b/heed/src/env.rs @@ -121,10 +121,10 @@ impl EnvOpenOptions { /// let env = env_builder.open(dir.path())?; /// /// // we will open the default unamed database - /// let db: Database> = env.create_database(None)?; + /// let mut wtxn = env.write_txn()?; + /// let db: Database> = env.create_database(&mut wtxn, None)?; /// /// // opening a write transaction - /// let mut wtxn = env.write_txn()?; /// db.put(&mut wtxn, "seven", &7)?; /// db.put(&mut wtxn, "zero", &0)?; /// db.put(&mut wtxn, "five", &5)?; @@ -513,7 +513,9 @@ mod tests { thread::sleep(Duration::from_secs(1)); }); - let db = env.create_database::(None).unwrap(); + let mut wtxn = env.write_txn().unwrap(); + let db = env.create_database::(&mut wtxn, None).unwrap(); + wtxn.commit().unwrap(); // Create an ordered list of keys... let mut wtxn = env.write_txn().unwrap(); @@ -574,6 +576,7 @@ mod tests { let dir = tempfile::tempdir().unwrap(); let mut envbuilder = EnvOpenOptions::new(); envbuilder.map_size(10 * 1024 * 1024); // 10MB + envbuilder.max_dbs(10); unsafe { envbuilder.flag(crate::flags::Flags::MdbWriteMap) }; let env = envbuilder.open(&dir.path()).unwrap(); diff --git a/heed/src/iter/mod.rs b/heed/src/iter/mod.rs index 453a04fc..ed56c979 100644 --- a/heed/src/iter/mod.rs +++ b/heed/src/iter/mod.rs @@ -36,7 +36,10 @@ mod tests { .max_dbs(3000) .open(dir.path()) .unwrap(); - let db = env.create_database::(None).unwrap(); + + let mut wtxn = env.write_txn().unwrap(); + let db = env.create_database::(&mut wtxn, None).unwrap(); + wtxn.commit().unwrap(); // Create an ordered list of keys... let mut wtxn = env.write_txn().unwrap(); @@ -73,7 +76,11 @@ mod tests { .max_dbs(3000) .open(dir.path()) .unwrap(); - let db = env.create_database::, Unit>(None).unwrap(); + + let mut wtxn = env.write_txn().unwrap(); + let db = env.create_database::, Unit>(&mut wtxn, None).unwrap(); + wtxn.commit().unwrap(); + type BEI32 = I32; // Create an ordered list of keys... @@ -137,7 +144,11 @@ mod tests { .max_dbs(3000) .open(dir.path()) .unwrap(); - let db = env.create_database::, Unit>(None).unwrap(); + + let mut wtxn = env.write_txn().unwrap(); + let db = env.create_database::, Unit>(&mut wtxn, None).unwrap(); + wtxn.commit().unwrap(); + type BEI32 = I32; // Create an ordered list of keys... @@ -224,7 +235,10 @@ mod tests { .max_dbs(3000) .open(dir.path()) .unwrap(); - let db = env.create_database::(None).unwrap(); + + let mut wtxn = env.write_txn().unwrap(); + let db = env.create_database::(&mut wtxn, None).unwrap(); + wtxn.commit().unwrap(); // Create an ordered list of keys... let mut wtxn = env.write_txn().unwrap(); @@ -296,7 +310,10 @@ mod tests { .max_dbs(3000) .open(dir.path()) .unwrap(); - let db = env.create_database::(None).unwrap(); + + let mut wtxn = env.write_txn().unwrap(); + let db = env.create_database::(&mut wtxn, None).unwrap(); + wtxn.commit().unwrap(); // Create an ordered list of keys... let mut wtxn = env.write_txn().unwrap(); @@ -369,7 +386,11 @@ mod tests { .max_dbs(3000) .open(dir.path()) .unwrap(); - let db = env.create_database::, Unit>(None).unwrap(); + + let mut wtxn = env.write_txn().unwrap(); + let db = env.create_database::, Unit>(&mut wtxn, None).unwrap(); + wtxn.commit().unwrap(); + type BEI32 = I32; // Create an ordered list of keys... diff --git a/heed/src/lib.rs b/heed/src/lib.rs index 141207ab..14d2fc50 100644 --- a/heed/src/lib.rs +++ b/heed/src/lib.rs @@ -25,10 +25,10 @@ //! let env = EnvOpenOptions::new().open(dir.path())?; //! //! // we will open the default unamed database -//! let db: Database> = env.create_database(None)?; +//! let mut wtxn = env.write_txn()?; +//! let db: Database> = env.create_database(&mut wtxn, None)?; //! //! // opening a write transaction -//! let mut wtxn = env.write_txn()?; //! db.put(&mut wtxn, "seven", &7)?; //! db.put(&mut wtxn, "zero", &0)?; //! db.put(&mut wtxn, "five", &5)?; From 975ebfb40a23e6ff1c7c9a036a38034181973aaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Thu, 15 Sep 2022 12:43:13 +0200 Subject: [PATCH 16/57] Fix the pkg_config in the build.rs --- lmdb-master3-sys/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lmdb-master3-sys/build.rs b/lmdb-master3-sys/build.rs index 213e3cc9..c6b14c25 100644 --- a/lmdb-master3-sys/build.rs +++ b/lmdb-master3-sys/build.rs @@ -59,7 +59,7 @@ fn main() { warn!("Building with `-fsanitize=fuzzer`."); } - if !pkg_config::find_library("liblmdb").is_ok() { + if !pkg_config::find_library("lmdb").is_ok() { let mut builder = cc::Build::new(); builder From 73983d9781c8578de9250d70601511ce0bb94e7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Thu, 15 Sep 2022 12:48:34 +0200 Subject: [PATCH 17/57] Remove useless MDBX related files --- heed/src/mdb/mdbx_error.rs | 0 heed/src/mdb/mdbx_ffi.rs | 0 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 heed/src/mdb/mdbx_error.rs delete mode 100644 heed/src/mdb/mdbx_ffi.rs diff --git a/heed/src/mdb/mdbx_error.rs b/heed/src/mdb/mdbx_error.rs deleted file mode 100644 index e69de29b..00000000 diff --git a/heed/src/mdb/mdbx_ffi.rs b/heed/src/mdb/mdbx_ffi.rs deleted file mode 100644 index e69de29b..00000000 From 997144f57f1bcb5bb18b27aeae77533efb504922 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Thu, 15 Sep 2022 12:51:08 +0200 Subject: [PATCH 18/57] Introduce a stale readers clearing Env method --- heed/src/env.rs | 11 +++++++++++ heed/src/mdb/lmdb_ffi.rs | 6 +++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/heed/src/env.rs b/heed/src/env.rs index ef7efc46..ebfd9bbc 100644 --- a/heed/src/env.rs +++ b/heed/src/env.rs @@ -465,6 +465,17 @@ impl Env { } } } + + /// Check for stale entries in the reader lock table and clear them. + /// + /// Returns the number of stale readers cleared. + pub fn clear_stale_readers(&self) -> Result { + let mut dead: i32 = 0; + unsafe { mdb_result(ffi::mdb_reader_check(self.0.env, &mut dead))? } + // safety: The reader_check function asks for an i32, initialize it to zero + // and never decrements it. It is safe to use either an u32 or u64 (usize). + Ok(dead as usize) + } } #[derive(Clone)] diff --git a/heed/src/mdb/lmdb_ffi.rs b/heed/src/mdb/lmdb_ffi.rs index f4de552c..683e1d0b 100644 --- a/heed/src/mdb/lmdb_ffi.rs +++ b/heed/src/mdb/lmdb_ffi.rs @@ -2,9 +2,9 @@ pub use ffi::{ mdb_cursor_close, mdb_cursor_del, mdb_cursor_get, mdb_cursor_open, mdb_cursor_put, mdb_dbi_open, mdb_del, mdb_drop, mdb_env_close, mdb_env_copyfd2 as mdb_env_copy2fd, mdb_env_create, mdb_env_open, mdb_env_set_mapsize, mdb_env_set_maxdbs, mdb_env_set_maxreaders, - mdb_env_stat, mdb_env_sync, mdb_filehandle_t, mdb_get, mdb_put, mdb_stat, mdb_txn_abort, - mdb_txn_begin, mdb_txn_commit, MDB_cursor, MDB_dbi, MDB_env, MDB_stat as MDB_Stat, MDB_txn, - MDB_APPEND, MDB_CP_COMPACT, MDB_CREATE, MDB_CURRENT, MDB_RDONLY, + mdb_env_stat, mdb_env_sync, mdb_filehandle_t, mdb_get, mdb_put, mdb_reader_check, mdb_stat, + mdb_txn_abort, mdb_txn_begin, mdb_txn_commit, MDB_cursor, MDB_dbi, MDB_env, + MDB_stat as MDB_Stat, MDB_txn, MDB_APPEND, MDB_CP_COMPACT, MDB_CREATE, MDB_CURRENT, MDB_RDONLY, }; use lmdb_master3_sys as ffi; From c8ac061ec4c40ef96a0e3dacc025e6bf07e1ed3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Thu, 15 Sep 2022 14:46:56 +0200 Subject: [PATCH 19/57] Document the limits of the unnamed database --- heed/src/env.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/heed/src/env.rs b/heed/src/env.rs index ebfd9bbc..d5ef5800 100644 --- a/heed/src/env.rs +++ b/heed/src/env.rs @@ -283,6 +283,12 @@ impl Env { /// Opens a typed database that already exists in this environment. /// /// If the database was previously opened in this program run, types will be checked. + /// + /// ## Important Information + /// + /// LMDB have an important restriction on the unnamed database when named ones are opened, + /// the names of the named databases are stored as keys in the unnamed one and are immutable, + /// these keys can only be read and not written. pub fn open_database( &self, rtxn: &RoTxn, @@ -303,6 +309,12 @@ impl Env { /// Opens an untyped database that already exists in this environment. /// /// If the database was previously opened as a typed one, an error will be returned. + /// + /// ## Important Information + /// + /// LMDB have an important restriction on the unnamed database when named ones are opened, + /// the names of the named databases are stored as keys in the unnamed one and are immutable, + /// these keys can only be read and not written. pub fn open_poly_database( &self, rtxn: &RoTxn, @@ -318,6 +330,12 @@ impl Env { /// Creates a typed database that can already exist in this environment. /// /// If the database was previously opened in this program run, types will be checked. + /// + /// ## Important Information + /// + /// LMDB have an important restriction on the unnamed database when named ones are opened, + /// the names of the named databases are stored as keys in the unnamed one and are immutable, + /// these keys can only be read and not written. pub fn create_database( &self, wtxn: &mut RwTxn, @@ -337,6 +355,12 @@ impl Env { /// Creates a typed database that can already exist in this environment. /// /// If the database was previously opened as a typed one, an error will be returned. + /// + /// ## Important Information + /// + /// LMDB have an important restriction on the unnamed database when named ones are opened, + /// the names of the named databases are stored as keys in the unnamed one and are immutable, + /// these keys can only be read and not written. pub fn create_poly_database( &self, wtxn: &mut RwTxn, From 852ba96e3edcec3269b363cd43a245884af57d12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Thu, 15 Sep 2022 15:18:21 +0200 Subject: [PATCH 20/57] Add a test that make sure Error is Send + Sync --- heed/src/lib.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/heed/src/lib.rs b/heed/src/lib.rs index 14d2fc50..a651044e 100644 --- a/heed/src/lib.rs +++ b/heed/src/lib.rs @@ -124,3 +124,16 @@ impl From for Error { } pub type Result = result::Result; + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn error_is_send_sync() { + fn give_me_send_sync(_: T) {} + + let error = Error::Encoding(Box::from("There is an issue, you know?")); + give_me_send_sync(error); + } +} From f477e2f749e0b2431fcf285329b6290d397e80a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Thu, 15 Sep 2022 15:54:09 +0200 Subject: [PATCH 21/57] Introduce a method to get environment information --- heed/src/env.rs | 37 +++++++++++++++++++++++++++++++++++-- heed/src/mdb/lmdb_ffi.rs | 9 +++++---- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/heed/src/env.rs b/heed/src/env.rs index d5ef5800..bf2a3b00 100644 --- a/heed/src/env.rs +++ b/heed/src/env.rs @@ -1,15 +1,15 @@ use std::any::TypeId; use std::collections::hash_map::{Entry, HashMap}; -use std::ffi::CString; #[cfg(windows)] use std::ffi::OsStr; +use std::ffi::{c_void, CString}; use std::fs::File; #[cfg(unix)] use std::os::unix::ffi::OsStrExt; use std::path::{Path, PathBuf}; use std::sync::{Arc, RwLock}; use std::time::Duration; -use std::{io, ptr, sync}; +use std::{io, mem, ptr, sync}; use once_cell::sync::Lazy; use synchronoise::event::SignalEvent; @@ -464,6 +464,22 @@ impl Env { &self.0.path } + /// Returns some basic informations about this environment. + pub fn info(&self) -> EnvInfo { + let mut raw_info = mem::MaybeUninit::uninit(); + unsafe { ffi::mdb_env_info(self.0.env, raw_info.as_mut_ptr()) }; + let raw_info = unsafe { raw_info.assume_init() }; + + EnvInfo { + map_addr: raw_info.me_mapaddr, + map_size: raw_info.me_mapsize, + last_page_number: raw_info.me_last_pgno, + last_txn_id: raw_info.me_last_txnid, + maximum_number_of_readers: raw_info.me_maxreaders, + number_of_readers: raw_info.me_numreaders, + } + } + /// Returns an `EnvClosingEvent` that can be used to wait for the closing event, /// multiple threads can wait on this event. /// @@ -502,6 +518,23 @@ impl Env { } } +/// Contains information about the environment. +#[derive(Debug, Clone, Copy)] +pub struct EnvInfo { + /// Address of map, if fixed. + pub map_addr: *mut c_void, + /// Size of the data memory map. + pub map_size: usize, + /// ID of the last used page. + pub last_page_number: usize, + /// ID of the last committed transaction. + pub last_txn_id: usize, + /// Maximum number of reader slots in the environment. + pub maximum_number_of_readers: u32, + /// Maximum number of reader slots used in the environment. + pub number_of_readers: u32, +} + #[derive(Clone)] pub struct EnvClosingEvent(Arc); diff --git a/heed/src/mdb/lmdb_ffi.rs b/heed/src/mdb/lmdb_ffi.rs index 683e1d0b..6abeb062 100644 --- a/heed/src/mdb/lmdb_ffi.rs +++ b/heed/src/mdb/lmdb_ffi.rs @@ -1,10 +1,11 @@ pub use ffi::{ mdb_cursor_close, mdb_cursor_del, mdb_cursor_get, mdb_cursor_open, mdb_cursor_put, mdb_dbi_open, mdb_del, mdb_drop, mdb_env_close, mdb_env_copyfd2 as mdb_env_copy2fd, - mdb_env_create, mdb_env_open, mdb_env_set_mapsize, mdb_env_set_maxdbs, mdb_env_set_maxreaders, - mdb_env_stat, mdb_env_sync, mdb_filehandle_t, mdb_get, mdb_put, mdb_reader_check, mdb_stat, - mdb_txn_abort, mdb_txn_begin, mdb_txn_commit, MDB_cursor, MDB_dbi, MDB_env, - MDB_stat as MDB_Stat, MDB_txn, MDB_APPEND, MDB_CP_COMPACT, MDB_CREATE, MDB_CURRENT, MDB_RDONLY, + mdb_env_create, mdb_env_info, mdb_env_open, mdb_env_set_mapsize, mdb_env_set_maxdbs, + mdb_env_set_maxreaders, mdb_env_stat, mdb_env_sync, mdb_filehandle_t, mdb_get, mdb_put, + mdb_reader_check, mdb_stat, mdb_txn_abort, mdb_txn_begin, mdb_txn_commit, MDB_cursor, MDB_dbi, + MDB_env, MDB_envinfo, MDB_stat as MDB_Stat, MDB_txn, MDB_APPEND, MDB_CP_COMPACT, MDB_CREATE, + MDB_CURRENT, MDB_RDONLY, }; use lmdb_master3_sys as ffi; From 8ec4a49679048490571a4cfeab0c79e0627d951c Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Wed, 21 Sep 2022 14:19:23 +0200 Subject: [PATCH 22/57] Make the env transaction matching verification more user friendly --- heed/src/db/polymorph.rs | 52 ++++++++++++++++++++-------------------- heed/src/lib.rs | 10 ++++++++ heed/src/txn.rs | 10 +++++++- 3 files changed, 45 insertions(+), 27 deletions(-) diff --git a/heed/src/db/polymorph.rs b/heed/src/db/polymorph.rs index 149a70d6..4093e870 100644 --- a/heed/src/db/polymorph.rs +++ b/heed/src/db/polymorph.rs @@ -155,7 +155,7 @@ impl PolyDatabase { KC: BytesEncode<'a>, DC: BytesDecode<'txn>, { - assert_eq!(self.env_ident, txn.env.env_mut_ptr() as usize); + assert_matching_env_txn!(self, txn); let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).map_err(Error::Encoding)?; @@ -229,7 +229,7 @@ impl PolyDatabase { KC: BytesEncode<'a> + BytesDecode<'txn>, DC: BytesDecode<'txn>, { - assert_eq!(self.env_ident, txn.env.env_mut_ptr() as usize); + assert_matching_env_txn!(self, txn); let mut cursor = RoCursor::new(txn, self.dbi)?; let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).map_err(Error::Encoding)?; @@ -297,7 +297,7 @@ impl PolyDatabase { KC: BytesEncode<'a> + BytesDecode<'txn>, DC: BytesDecode<'txn>, { - assert_eq!(self.env_ident, txn.env.env_mut_ptr() as usize); + assert_matching_env_txn!(self, txn); let mut cursor = RoCursor::new(txn, self.dbi)?; let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).map_err(Error::Encoding)?; @@ -369,7 +369,7 @@ impl PolyDatabase { KC: BytesEncode<'a> + BytesDecode<'txn>, DC: BytesDecode<'txn>, { - assert_eq!(self.env_ident, txn.env.env_mut_ptr() as usize); + assert_matching_env_txn!(self, txn); let mut cursor = RoCursor::new(txn, self.dbi)?; let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).map_err(Error::Encoding)?; @@ -440,7 +440,7 @@ impl PolyDatabase { KC: BytesEncode<'a> + BytesDecode<'txn>, DC: BytesDecode<'txn>, { - assert_eq!(self.env_ident, txn.env.env_mut_ptr() as usize); + assert_matching_env_txn!(self, txn); let mut cursor = RoCursor::new(txn, self.dbi)?; let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).map_err(Error::Encoding)?; @@ -494,7 +494,7 @@ impl PolyDatabase { KC: BytesDecode<'txn>, DC: BytesDecode<'txn>, { - assert_eq!(self.env_ident, txn.env.env_mut_ptr() as usize); + assert_matching_env_txn!(self, txn); let mut cursor = RoCursor::new(txn, self.dbi)?; match cursor.move_on_first() { @@ -547,7 +547,7 @@ impl PolyDatabase { KC: BytesDecode<'txn>, DC: BytesDecode<'txn>, { - assert_eq!(self.env_ident, txn.env.env_mut_ptr() as usize); + assert_matching_env_txn!(self, txn); let mut cursor = RoCursor::new(txn, self.dbi)?; match cursor.move_on_last() { @@ -600,7 +600,7 @@ impl PolyDatabase { /// # Ok(()) } /// ``` pub fn len<'txn>(&self, txn: &'txn RoTxn) -> Result { - assert_eq!(self.env_ident, txn.env.env_mut_ptr() as usize); + assert_matching_env_txn!(self, txn); let mut db_stat = mem::MaybeUninit::uninit(); let result = unsafe { mdb_result(ffi::mdb_stat(txn.txn, self.dbi, db_stat.as_mut_ptr())) }; @@ -653,7 +653,7 @@ impl PolyDatabase { /// # Ok(()) } /// ``` pub fn is_empty<'txn>(&self, txn: &'txn RoTxn) -> Result { - assert_eq!(self.env_ident, txn.env.env_mut_ptr() as usize); + assert_matching_env_txn!(self, txn); let mut cursor = RoCursor::new(txn, self.dbi)?; match cursor.move_on_first()? { @@ -699,7 +699,7 @@ impl PolyDatabase { /// # Ok(()) } /// ``` pub fn iter<'txn, KC, DC>(&self, txn: &'txn RoTxn) -> Result> { - assert_eq!(self.env_ident, txn.env.env_mut_ptr() as usize); + assert_matching_env_txn!(self, txn); RoCursor::new(txn, self.dbi).map(|cursor| RoIter::new(cursor)) } @@ -754,7 +754,7 @@ impl PolyDatabase { /// # Ok(()) } /// ``` pub fn iter_mut<'txn, KC, DC>(&self, txn: &'txn mut RwTxn) -> Result> { - assert_eq!(self.env_ident, txn.txn.env.env_mut_ptr() as usize); + assert_matching_env_txn!(self, txn); RwCursor::new(txn, self.dbi).map(|cursor| RwIter::new(cursor)) } @@ -796,7 +796,7 @@ impl PolyDatabase { /// # Ok(()) } /// ``` pub fn rev_iter<'txn, KC, DC>(&self, txn: &'txn RoTxn) -> Result> { - assert_eq!(self.env_ident, txn.env.env_mut_ptr() as usize); + assert_matching_env_txn!(self, txn); RoCursor::new(txn, self.dbi).map(|cursor| RoRevIter::new(cursor)) } @@ -855,7 +855,7 @@ impl PolyDatabase { &self, txn: &'txn mut RwTxn, ) -> Result> { - assert_eq!(self.env_ident, txn.env.env_mut_ptr() as usize); + assert_matching_env_txn!(self, txn); RwCursor::new(txn, self.dbi).map(|cursor| RwRevIter::new(cursor)) } @@ -908,7 +908,7 @@ impl PolyDatabase { KC: BytesEncode<'a>, R: RangeBounds, { - assert_eq!(self.env_ident, txn.env.env_mut_ptr() as usize); + assert_matching_env_txn!(self, txn); let start_bound = match range.start_bound() { Bound::Included(bound) => { @@ -999,7 +999,7 @@ impl PolyDatabase { KC: BytesEncode<'a>, R: RangeBounds, { - assert_eq!(self.env_ident, txn.txn.env.env_mut_ptr() as usize); + assert_matching_env_txn!(self, txn); let start_bound = match range.start_bound() { Bound::Included(bound) => { @@ -1077,7 +1077,7 @@ impl PolyDatabase { KC: BytesEncode<'a>, R: RangeBounds, { - assert_eq!(self.env_ident, txn.env.env_mut_ptr() as usize); + assert_matching_env_txn!(self, txn); let start_bound = match range.start_bound() { Bound::Included(bound) => { @@ -1168,7 +1168,7 @@ impl PolyDatabase { KC: BytesEncode<'a>, R: RangeBounds, { - assert_eq!(self.env_ident, txn.txn.env.env_mut_ptr() as usize); + assert_matching_env_txn!(self, txn); let start_bound = match range.start_bound() { Bound::Included(bound) => { @@ -1246,7 +1246,7 @@ impl PolyDatabase { where KC: BytesEncode<'a>, { - assert_eq!(self.env_ident, txn.env.env_mut_ptr() as usize); + assert_matching_env_txn!(self, txn); let prefix_bytes = KC::bytes_encode(prefix).map_err(Error::Encoding)?; let prefix_bytes = prefix_bytes.into_owned(); @@ -1315,7 +1315,7 @@ impl PolyDatabase { where KC: BytesEncode<'a>, { - assert_eq!(self.env_ident, txn.txn.env.env_mut_ptr() as usize); + assert_matching_env_txn!(self, txn); let prefix_bytes = KC::bytes_encode(prefix).map_err(Error::Encoding)?; let prefix_bytes = prefix_bytes.into_owned(); @@ -1371,7 +1371,7 @@ impl PolyDatabase { where KC: BytesEncode<'a>, { - assert_eq!(self.env_ident, txn.env.env_mut_ptr() as usize); + assert_matching_env_txn!(self, txn); let prefix_bytes = KC::bytes_encode(prefix).map_err(Error::Encoding)?; let prefix_bytes = prefix_bytes.into_owned(); @@ -1440,7 +1440,7 @@ impl PolyDatabase { where KC: BytesEncode<'a>, { - assert_eq!(self.env_ident, txn.txn.env.env_mut_ptr() as usize); + assert_matching_env_txn!(self, txn); let prefix_bytes = KC::bytes_encode(prefix).map_err(Error::Encoding)?; let prefix_bytes = prefix_bytes.into_owned(); @@ -1490,7 +1490,7 @@ impl PolyDatabase { KC: BytesEncode<'a>, DC: BytesEncode<'a>, { - assert_eq!(self.env_ident, txn.txn.env.env_mut_ptr() as usize); + assert_matching_env_txn!(self, txn); let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).map_err(Error::Encoding)?; let data_bytes: Cow<[u8]> = DC::bytes_encode(&data).map_err(Error::Encoding)?; @@ -1552,7 +1552,7 @@ impl PolyDatabase { KC: BytesEncode<'a>, DC: BytesEncode<'a>, { - assert_eq!(self.env_ident, txn.txn.env.env_mut_ptr() as usize); + assert_matching_env_txn!(self, txn); let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).map_err(Error::Encoding)?; let data_bytes: Cow<[u8]> = DC::bytes_encode(&data).map_err(Error::Encoding)?; @@ -1613,7 +1613,7 @@ impl PolyDatabase { where KC: BytesEncode<'a>, { - assert_eq!(self.env_ident, txn.txn.env.env_mut_ptr() as usize); + assert_matching_env_txn!(self, txn); let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).map_err(Error::Encoding)?; let mut key_val = unsafe { crate::into_val(&key_bytes) }; @@ -1681,7 +1681,7 @@ impl PolyDatabase { KC: BytesEncode<'a> + BytesDecode<'txn>, R: RangeBounds, { - assert_eq!(self.env_ident, txn.txn.env.env_mut_ptr() as usize); + assert_matching_env_txn!(self, txn); let mut count = 0; let mut iter = self.range_mut::(txn, range)?; @@ -1738,7 +1738,7 @@ impl PolyDatabase { /// # Ok(()) } /// ``` pub fn clear(&self, txn: &mut RwTxn) -> Result<()> { - assert_eq!(self.env_ident, txn.txn.env.env_mut_ptr() as usize); + assert_matching_env_txn!(self, txn); unsafe { mdb_result(ffi::mdb_drop(txn.txn.txn, self.dbi, 0)).map_err(Into::into) } } diff --git a/heed/src/lib.rs b/heed/src/lib.rs index a651044e..96f09d41 100644 --- a/heed/src/lib.rs +++ b/heed/src/lib.rs @@ -137,3 +137,13 @@ mod tests { give_me_send_sync(error); } } + +#[macro_export] +macro_rules! assert_matching_env_txn { + ($database:ident, $txn:ident) => { + assert!( + $database.env_ident == $txn.env_mut_ptr() as usize, + "The database environment doesn't match the transaction's environment" + ); + }; +} diff --git a/heed/src/txn.rs b/heed/src/txn.rs index 0bdd9317..e42f8c7c 100644 --- a/heed/src/txn.rs +++ b/heed/src/txn.rs @@ -7,7 +7,7 @@ use crate::{Env, Result}; pub struct RoTxn<'e> { pub(crate) txn: *mut ffi::MDB_txn, - pub(crate) env: &'e Env, + env: &'e Env, } impl<'e> RoTxn<'e> { @@ -26,6 +26,10 @@ impl<'e> RoTxn<'e> { Ok(RoTxn { txn, env }) } + pub(crate) fn env_mut_ptr(&self) -> *mut ffi::MDB_env { + self.env.env_mut_ptr() + } + pub fn commit(mut self) -> Result<()> { let result = unsafe { mdb_result(ffi::mdb_txn_commit(self.txn)) }; self.txn = ptr::null_mut(); @@ -79,6 +83,10 @@ impl<'e> RwTxn<'e, 'e> { Ok(RwTxn { txn: RoTxn { txn, env }, _parent: marker::PhantomData }) } + pub(crate) fn env_mut_ptr(&self) -> *mut ffi::MDB_env { + self.txn.env.env_mut_ptr() + } + pub fn commit(self) -> Result<()> { self.txn.commit() } From f24a77a38f8781b34265fe3e38506395fb69aa64 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Wed, 21 Sep 2022 15:37:02 +0200 Subject: [PATCH 23/57] Introduce the ReservedSpace structure --- heed/src/lib.rs | 2 ++ heed/src/mdb/lmdb_ffi.rs | 10 +++++++-- heed/src/reserved_space.rs | 45 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 heed/src/reserved_space.rs diff --git a/heed/src/lib.rs b/heed/src/lib.rs index 96f09d41..fe17c750 100644 --- a/heed/src/lib.rs +++ b/heed/src/lib.rs @@ -53,6 +53,7 @@ mod env; mod iter; mod lazy_decode; mod mdb; +mod reserved_space; mod txn; use std::{error, fmt, io, result}; @@ -71,6 +72,7 @@ pub use self::lazy_decode::{Lazy, LazyDecode}; pub use self::mdb::error::Error as MdbError; use self::mdb::ffi::{from_val, into_val}; pub use self::mdb::flags; +pub use self::reserved_space::ReservedSpace; pub use self::traits::{BoxedError, BytesDecode, BytesEncode}; pub use self::txn::{RoTxn, RwTxn}; diff --git a/heed/src/mdb/lmdb_ffi.rs b/heed/src/mdb/lmdb_ffi.rs index 6abeb062..e2b07993 100644 --- a/heed/src/mdb/lmdb_ffi.rs +++ b/heed/src/mdb/lmdb_ffi.rs @@ -1,11 +1,13 @@ +use std::ptr; + pub use ffi::{ mdb_cursor_close, mdb_cursor_del, mdb_cursor_get, mdb_cursor_open, mdb_cursor_put, mdb_dbi_open, mdb_del, mdb_drop, mdb_env_close, mdb_env_copyfd2 as mdb_env_copy2fd, mdb_env_create, mdb_env_info, mdb_env_open, mdb_env_set_mapsize, mdb_env_set_maxdbs, mdb_env_set_maxreaders, mdb_env_stat, mdb_env_sync, mdb_filehandle_t, mdb_get, mdb_put, mdb_reader_check, mdb_stat, mdb_txn_abort, mdb_txn_begin, mdb_txn_commit, MDB_cursor, MDB_dbi, - MDB_env, MDB_envinfo, MDB_stat as MDB_Stat, MDB_txn, MDB_APPEND, MDB_CP_COMPACT, MDB_CREATE, - MDB_CURRENT, MDB_RDONLY, + MDB_env, MDB_envinfo, MDB_stat as MDB_Stat, MDB_txn, MDB_val, MDB_APPEND, MDB_CP_COMPACT, + MDB_CREATE, MDB_CURRENT, MDB_RDONLY, MDB_RESERVE, }; use lmdb_master3_sys as ffi; @@ -20,6 +22,10 @@ pub mod cursor_op { pub const MDB_GET_CURRENT: MDB_cursor_op = ffi::MDB_GET_CURRENT; } +pub fn reserve_size_val(size: usize) -> ffi::MDB_val { + ffi::MDB_val { mv_size: size, mv_data: ptr::null_mut() } +} + pub unsafe fn into_val(value: &[u8]) -> ffi::MDB_val { ffi::MDB_val { mv_data: value.as_ptr() as *mut libc::c_void, mv_size: value.len() } } diff --git a/heed/src/reserved_space.rs b/heed/src/reserved_space.rs new file mode 100644 index 00000000..81874d8c --- /dev/null +++ b/heed/src/reserved_space.rs @@ -0,0 +1,45 @@ +use std::io; + +use crate::mdb::ffi; + +/// A structure that is used to improve the write speed in LMDB. +/// +/// You must write the exact amount of bytes, no less, no more. +pub struct ReservedSpace { + size: usize, + start_ptr: *mut u8, + written: usize, +} + +impl ReservedSpace { + pub(crate) unsafe fn from_val(val: ffi::MDB_val) -> ReservedSpace { + ReservedSpace { size: val.mv_size, start_ptr: val.mv_data as *mut u8, written: 0 } + } + + /// The total number of bytes that this memory buffer is. + pub fn size(&self) -> usize { + self.size + } + + /// The remaining number of bytes that this memory buffer has. + pub fn remaining(&self) -> usize { + self.size - self.written + } +} + +impl io::Write for ReservedSpace { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.remaining() >= buf.len() { + let dest = unsafe { self.start_ptr.add(self.written) }; + unsafe { buf.as_ptr().copy_to_nonoverlapping(dest, buf.len()) }; + self.written += buf.len(); + Ok(buf.len()) + } else { + Err(io::Error::from(io::ErrorKind::WriteZero)) + } + } + + fn flush(&mut self) -> io::Result<()> { + Ok(()) + } +} From 690b1af6654242ede584921b66f7d968d99b1b84 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Wed, 21 Sep 2022 15:49:14 +0200 Subject: [PATCH 24/57] Introduce the PolyDatabase::put_reserved method --- heed/src/db/polymorph.rs | 67 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/heed/src/db/polymorph.rs b/heed/src/db/polymorph.rs index 4093e870..499325a0 100644 --- a/heed/src/db/polymorph.rs +++ b/heed/src/db/polymorph.rs @@ -1447,7 +1447,7 @@ impl PolyDatabase { RwCursor::new(txn, self.dbi).map(|cursor| RwRevPrefix::new(cursor, prefix_bytes)) } - /// Insert a key-value pairs in this database. + /// Insert a key-value pair in this database. /// /// ``` /// # use std::fs; @@ -1506,6 +1506,71 @@ impl PolyDatabase { Ok(()) } + /// Insert a key-value pair where the value can directly be written to disk. + /// + /// ``` + /// # use std::fs; + /// # use std::path::Path; + /// # use heed::EnvOpenOptions; + /// use std::io::Write; + /// use heed::Database; + /// use heed::types::*; + /// use heed::byteorder::BigEndian; + /// + /// # fn main() -> Result<(), Box> { + /// # let dir = tempfile::tempdir()?; + /// # let env = EnvOpenOptions::new() + /// # .map_size(10 * 1024 * 1024) // 10MB + /// # .max_dbs(3000) + /// # .open(dir.path())?; + /// type BEI32 = I32; + /// + /// let mut wtxn = env.write_txn()?; + /// let db = env.create_poly_database(&mut wtxn, Some("iter-i32"))?; + /// + /// # db.clear(&mut wtxn)?; + /// let value = "I am a long long long value"; + /// db.put_reserved::, _>(&mut wtxn, &BEI32::new(42), value.len(), |reserved| { + /// reserved.write_all(value.as_bytes()) + /// })?; + /// + /// let ret = db.get::, Str>(&mut wtxn, &BEI32::new(42))?; + /// assert_eq!(ret, Some(value)); + /// + /// wtxn.commit()?; + /// # Ok(()) } + /// ``` + pub fn put_reserved<'a, KC, F>( + &self, + txn: &mut RwTxn, + key: &'a KC::EItem, + data_size: usize, + mut write_func: F, + ) -> Result<()> + where + KC: BytesEncode<'a>, + F: FnMut(&mut ReservedSpace) -> io::Result<()>, + { + assert_matching_env_txn!(self, txn); + + let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).map_err(Error::Encoding)?; + let mut key_val = unsafe { crate::into_val(&key_bytes) }; + let mut reserved = ffi::reserve_size_val(data_size); + let flags = ffi::MDB_RESERVE; + + unsafe { + mdb_result(ffi::mdb_put(txn.txn.txn, self.dbi, &mut key_val, &mut reserved, flags))? + } + + let mut reserved = unsafe { ReservedSpace::from_val(reserved) }; + (write_func)(&mut reserved)?; + if reserved.remaining() == 0 { + Ok(()) + } else { + Err(io::Error::from(io::ErrorKind::UnexpectedEof).into()) + } + } + /// Append the given key/data pair to the end of the database. /// /// This option allows fast bulk loading when keys are already known to be in the correct order. From b273a2d1a1e2b4b2a71be1f55d0a0abb986325c0 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Thu, 22 Sep 2022 11:39:40 +0200 Subject: [PATCH 25/57] Introduce the iterator put_current_reserved methods --- heed/src/cursor.rs | 45 +++++++++++++++ heed/src/iter/iter.rs | 54 ++++++++++++++++++ heed/src/iter/prefix.rs | 54 ++++++++++++++++++ heed/src/iter/range.rs | 54 ++++++++++++++++++ .../tests/fixtures/testdb/data.mdb | Bin 180224 -> 180224 bytes .../tests/fixtures/testdb/lock.mdb | Bin 8128 -> 8128 bytes 6 files changed, 207 insertions(+) diff --git a/heed/src/cursor.rs b/heed/src/cursor.rs index 476959f9..8a4238b1 100644 --- a/heed/src/cursor.rs +++ b/heed/src/cursor.rs @@ -254,6 +254,51 @@ impl<'txn> RwCursor<'txn> { } } + /// Write a new value to the current entry. + /// + /// The given key **must** be equal to the one this cursor is pointing otherwise the database + /// can be put into an inconsistent state. + /// + /// Returns `true` if the entry was successfully written. + /// + /// > This is intended to be used when the new data is the same size as the old. + /// > Otherwise it will simply perform a delete of the old record followed by an insert. + /// + /// # Safety + /// + /// Please read the safety notes of the `[put_current]` method. + pub unsafe fn put_current_reserved( + &mut self, + key: &[u8], + data_size: usize, + mut write_func: F, + ) -> Result + where + F: FnMut(&mut ReservedSpace) -> io::Result<()>, + { + let mut key_val = crate::into_val(&key); + let mut reserved = ffi::reserve_size_val(data_size); + let flags = ffi::MDB_RESERVE; + + let result = + mdb_result(ffi::mdb_cursor_put(self.cursor.cursor, &mut key_val, &mut reserved, flags)); + + let found = match result { + Ok(()) => true, + Err(e) if e.not_found() => false, + Err(e) => return Err(e.into()), + }; + + let mut reserved = ReservedSpace::from_val(reserved); + (write_func)(&mut reserved)?; + + if reserved.remaining() == 0 { + Ok(found) + } else { + Err(io::Error::from(io::ErrorKind::UnexpectedEof).into()) + } + } + /// Append the given key/value pair to the end of the database. /// /// If a key is inserted that is less than any previous key a `KeyExist` error diff --git a/heed/src/iter/iter.rs b/heed/src/iter/iter.rs index 804e814f..d5af37b1 100644 --- a/heed/src/iter/iter.rs +++ b/heed/src/iter/iter.rs @@ -153,6 +153,33 @@ impl<'txn, KC, DC> RwIter<'txn, KC, DC> { self.cursor.put_current(&key_bytes, &data_bytes) } + /// Write a new value to the current entry. + /// + /// The given key **must** be equal to the one this cursor is pointing otherwise the database + /// can be put into an inconsistent state. + /// + /// Returns `true` if the entry was successfully written. + /// + /// > This is intended to be used when the new data is the same size as the old. + /// > Otherwise it will simply perform a delete of the old record followed by an insert. + /// + /// # Safety + /// + /// Please read the safety notes of the [`RwIter::put_current`] method. + pub unsafe fn put_current_reserved<'a, F>( + &mut self, + key: &'a KC::EItem, + data_size: usize, + write_func: F, + ) -> Result + where + KC: BytesEncode<'a>, + F: FnMut(&mut ReservedSpace) -> io::Result<()>, + { + let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).map_err(Error::Encoding)?; + self.cursor.put_current_reserved(&key_bytes, data_size, write_func) + } + /// Append the given key/value pair to the end of the database. /// /// If a key is inserted that is less than any previous key a `KeyExist` error @@ -405,6 +432,33 @@ impl<'txn, KC, DC> RwRevIter<'txn, KC, DC> { self.cursor.put_current(&key_bytes, &data_bytes) } + /// Write a new value to the current entry. + /// + /// The given key **must** be equal to the one this cursor is pointing otherwise the database + /// can be put into an inconsistent state. + /// + /// Returns `true` if the entry was successfully written. + /// + /// > This is intended to be used when the new data is the same size as the old. + /// > Otherwise it will simply perform a delete of the old record followed by an insert. + /// + /// # Safety + /// + /// Please read the safety notes of the [`RwRevIter::put_current`] method. + pub unsafe fn put_current_reserved<'a, F>( + &mut self, + key: &'a KC::EItem, + data_size: usize, + write_func: F, + ) -> Result + where + KC: BytesEncode<'a>, + F: FnMut(&mut ReservedSpace) -> io::Result<()>, + { + let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).map_err(Error::Encoding)?; + self.cursor.put_current_reserved(&key_bytes, data_size, write_func) + } + /// Append the given key/value pair to the end of the database. /// /// If a key is inserted that is less than any previous key a `KeyExist` error diff --git a/heed/src/iter/prefix.rs b/heed/src/iter/prefix.rs index 9941613d..d2d84628 100644 --- a/heed/src/iter/prefix.rs +++ b/heed/src/iter/prefix.rs @@ -180,6 +180,33 @@ impl<'txn, KC, DC> RwPrefix<'txn, KC, DC> { self.cursor.put_current(&key_bytes, &data_bytes) } + /// Write a new value to the current entry. + /// + /// The given key **must** be equal to the one this cursor is pointing otherwise the database + /// can be put into an inconsistent state. + /// + /// Returns `true` if the entry was successfully written. + /// + /// > This is intended to be used when the new data is the same size as the old. + /// > Otherwise it will simply perform a delete of the old record followed by an insert. + /// + /// # Safety + /// + /// Please read the safety notes of the [`RwPrefix::put_current`] method. + pub unsafe fn put_current_reserved<'a, F>( + &mut self, + key: &'a KC::EItem, + data_size: usize, + write_func: F, + ) -> Result + where + KC: BytesEncode<'a>, + F: FnMut(&mut ReservedSpace) -> io::Result<()>, + { + let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).map_err(Error::Encoding)?; + self.cursor.put_current_reserved(&key_bytes, data_size, write_func) + } + /// Append the given key/value pair to the end of the database. /// /// If a key is inserted that is less than any previous key a `KeyExist` error @@ -462,6 +489,33 @@ impl<'txn, KC, DC> RwRevPrefix<'txn, KC, DC> { self.cursor.put_current(&key_bytes, &data_bytes) } + /// Write a new value to the current entry. + /// + /// The given key **must** be equal to the one this cursor is pointing otherwise the database + /// can be put into an inconsistent state. + /// + /// Returns `true` if the entry was successfully written. + /// + /// > This is intended to be used when the new data is the same size as the old. + /// > Otherwise it will simply perform a delete of the old record followed by an insert. + /// + /// # Safety + /// + /// Please read the safety notes of the [`RwRevPrefix::put_current`] method. + pub unsafe fn put_current_reserved<'a, F>( + &mut self, + key: &'a KC::EItem, + data_size: usize, + write_func: F, + ) -> Result + where + KC: BytesEncode<'a>, + F: FnMut(&mut ReservedSpace) -> io::Result<()>, + { + let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).map_err(Error::Encoding)?; + self.cursor.put_current_reserved(&key_bytes, data_size, write_func) + } + /// Append the given key/value pair to the end of the database. /// /// If a key is inserted that is less than any previous key a `KeyExist` error diff --git a/heed/src/iter/range.rs b/heed/src/iter/range.rs index 9e51825a..196c464a 100644 --- a/heed/src/iter/range.rs +++ b/heed/src/iter/range.rs @@ -238,6 +238,33 @@ impl<'txn, KC, DC> RwRange<'txn, KC, DC> { self.cursor.put_current(&key_bytes, &data_bytes) } + /// Write a new value to the current entry. + /// + /// The given key **must** be equal to the one this cursor is pointing otherwise the database + /// can be put into an inconsistent state. + /// + /// Returns `true` if the entry was successfully written. + /// + /// > This is intended to be used when the new data is the same size as the old. + /// > Otherwise it will simply perform a delete of the old record followed by an insert. + /// + /// # Safety + /// + /// Please read the safety notes of the [`RwRange::put_current`] method. + pub unsafe fn put_current_reserved<'a, F>( + &mut self, + key: &'a KC::EItem, + data_size: usize, + write_func: F, + ) -> Result + where + KC: BytesEncode<'a>, + F: FnMut(&mut ReservedSpace) -> io::Result<()>, + { + let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).map_err(Error::Encoding)?; + self.cursor.put_current_reserved(&key_bytes, data_size, write_func) + } + /// Append the given key/value pair to the end of the database. /// /// If a key is inserted that is less than any previous key a `KeyExist` error @@ -568,6 +595,33 @@ impl<'txn, KC, DC> RwRevRange<'txn, KC, DC> { self.cursor.put_current(&key_bytes, &data_bytes) } + /// Write a new value to the current entry. + /// + /// The given key **must** be equal to the one this cursor is pointing otherwise the database + /// can be put into an inconsistent state. + /// + /// Returns `true` if the entry was successfully written. + /// + /// > This is intended to be used when the new data is the same size as the old. + /// > Otherwise it will simply perform a delete of the old record followed by an insert. + /// + /// # Safety + /// + /// Please read the safety notes of the [`RwRevRange::put_current`] method. + pub unsafe fn put_current_reserved<'a, F>( + &mut self, + key: &'a KC::EItem, + data_size: usize, + write_func: F, + ) -> Result + where + KC: BytesEncode<'a>, + F: FnMut(&mut ReservedSpace) -> io::Result<()>, + { + let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).map_err(Error::Encoding)?; + self.cursor.put_current_reserved(&key_bytes, data_size, write_func) + } + /// Append the given key/value pair to the end of the database. /// /// If a key is inserted that is less than any previous key a `KeyExist` error diff --git a/lmdb-master3-sys/tests/fixtures/testdb/data.mdb b/lmdb-master3-sys/tests/fixtures/testdb/data.mdb index 000798b6bd6b44a489ae2c6baa5671733126bd58..9de4a10fb605133355dafb41a474bfc961c263ce 100644 GIT binary patch delta 149 zcmZo@;BIK(W@MPm=rEm;W8=bj`-vMkCOJefa!!oY=VW4l0IrFFq8rx*f#fCz2yGT> z*knI3fMW_1$K)&fO&B>gb2jX@pVS~Q`O1GFZ!0I`|No5aKl_*J$nEE diff --git a/lmdb-master3-sys/tests/fixtures/testdb/lock.mdb b/lmdb-master3-sys/tests/fixtures/testdb/lock.mdb index 2ea5dccd82e97e524819f9f482b5d99af2408a3e..5c3da772cea684bc39ef06dd8cf83934049784af 100644 GIT binary patch delta 55 zcmX?Lf52Yh-hub~m>9w}I2a&+5lS!k^EWZ9w}*cc#y5lYXo>Da#i&oqIFi3$@P1X&6eW;1R~jF+Eizykos Cx)3}7 From eae34aae7e2e7238e644dc9156fc7ebaf117f811 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Thu, 22 Sep 2022 11:39:03 +0200 Subject: [PATCH 26/57] Bump to edition 2021 --- heed-traits/Cargo.toml | 2 +- heed-types/Cargo.toml | 2 +- heed/Cargo.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/heed-traits/Cargo.toml b/heed-traits/Cargo.toml index 679cd997..2ccffee8 100644 --- a/heed-traits/Cargo.toml +++ b/heed-traits/Cargo.toml @@ -6,6 +6,6 @@ description = "The traits used inside of the fully typed LMDB wrapper, heed" license = "MIT" repository = "https://github.com/Kerollmops/heed" readme = "../README.md" -edition = "2018" +edition = "2021" [dependencies] diff --git a/heed-types/Cargo.toml b/heed-types/Cargo.toml index 8ea1b9ce..61d751f7 100644 --- a/heed-types/Cargo.toml +++ b/heed-types/Cargo.toml @@ -6,7 +6,7 @@ description = "The types used with the fully typed LMDB wrapper, heed" license = "MIT" repository = "https://github.com/Kerollmops/heed" readme = "../README.md" -edition = "2018" +edition = "2021" [dependencies] bincode = { version = "1.3.3", optional = true } diff --git a/heed/Cargo.toml b/heed/Cargo.toml index 10ff6b01..5fa5fc32 100644 --- a/heed/Cargo.toml +++ b/heed/Cargo.toml @@ -8,7 +8,7 @@ repository = "https://github.com/Kerollmops/heed" keywords = ["lmdb", "database", "storage", "typed"] categories = ["database", "data-structures"] readme = "../README.md" -edition = "2018" +edition = "2021" [dependencies] bytemuck = "1.12.1" From 4b656380219ada931859306e4b4ae9f3cec42c98 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Thu, 22 Sep 2022 14:00:21 +0200 Subject: [PATCH 27/57] Add Env information functions Co-authored-by: irevoire --- heed/src/env.rs | 201 +++++++++++++++++++++++++++++---------- heed/src/lib.rs | 4 +- heed/src/mdb/lmdb_ffi.rs | 12 +-- 3 files changed, 161 insertions(+), 56 deletions(-) diff --git a/heed/src/env.rs b/heed/src/env.rs index bf2a3b00..fae9a7c7 100644 --- a/heed/src/env.rs +++ b/heed/src/env.rs @@ -1,14 +1,20 @@ use std::any::TypeId; use std::collections::hash_map::{Entry, HashMap}; -#[cfg(windows)] -use std::ffi::OsStr; use std::ffi::{c_void, CString}; -use std::fs::File; +use std::fs::{File, Metadata}; #[cfg(unix)] -use std::os::unix::ffi::OsStrExt; +use std::os::unix::{ + ffi::OsStrExt, + io::{AsRawFd, BorrowedFd, RawFd}, +}; use std::path::{Path, PathBuf}; use std::sync::{Arc, RwLock}; use std::time::Duration; +#[cfg(windows)] +use std::{ + ffi::OsStr, + os::windows::io::{AsRawHandle, BorrowedHandle, RawHandle}, +}; use std::{io, mem, ptr, sync}; use once_cell::sync::Lazy; @@ -17,7 +23,7 @@ use synchronoise::event::SignalEvent; use crate::flags::Flags; use crate::mdb::error::mdb_result; use crate::mdb::ffi; -use crate::{Database, Error, PolyDatabase, Result, RoTxn, RwTxn}; +use crate::{Database, Error, PolyDatabase, Result, RoCursor, RoTxn, RwTxn}; /// The list of opened environments, the value is an optional environment, it is None /// when someone asks to close the environment, closing is a two-phase step, to make sure @@ -61,16 +67,30 @@ impl OsStrExtLmdb for OsStr { } } +#[cfg(unix)] +fn get_file_fd(file: &File) -> RawFd { + file.as_raw_fd() +} + #[cfg(windows)] -fn get_file_fd(file: &File) -> std::os::windows::io::RawHandle { - use std::os::windows::io::AsRawHandle; +fn get_file_fd(file: &File) -> RawHandle { file.as_raw_handle() } #[cfg(unix)] -fn get_file_fd(file: &File) -> std::os::unix::io::RawFd { - use std::os::unix::io::AsRawFd; - file.as_raw_fd() +/// Get metadata from a file descriptor. +unsafe fn metadata_from_fd(raw_fd: RawFd) -> io::Result { + let fd = BorrowedFd::borrow_raw(raw_fd); + let owned = fd.try_clone_to_owned()?; + File::from(owned).metadata() +} + +#[cfg(windows)] +/// Get metadata from a file descriptor. +unsafe fn metadata_from_fd(raw_fd: RawHandle) -> io::Result { + let fd = BorrowedHandle::borrow_raw(raw_fd); + let owned = fd.try_clone_to_owned()?; + File::from(owned).metadata() } #[derive(Clone, Debug, PartialEq)] @@ -280,6 +300,109 @@ impl Env { self.0.env } + /// The size of the data file on disk. + /// + /// # Example + /// + /// ``` + /// use heed::EnvOpenOptions; + /// + /// # fn main() -> Result<(), Box> { + /// let dir = tempfile::tempdir()?; + /// let size_in_bytes = 1024 * 1024; + /// let env = EnvOpenOptions::new().map_size(size_in_bytes).open(dir.path())?; + /// + /// let actual_size = env.real_disk_size()? as usize; + /// assert!(actual_size < size_in_bytes); + /// # Ok(()) } + /// ``` + pub fn real_disk_size(&self) -> Result { + let mut fd = std::mem::MaybeUninit::uninit(); + unsafe { mdb_result(ffi::mdb_env_get_fd(self.env_mut_ptr(), fd.as_mut_ptr()))? }; + let fd = unsafe { fd.assume_init() }; + let metadata = unsafe { metadata_from_fd(fd)? }; + Ok(metadata.len()) + } + + /// Check if a flag was specified when opening this environment. + pub fn contains_flag(&self, flag: Flags) -> Result { + let flags = self.raw_flags()?; + let set = flags & (flag as u32); + Ok(set != 0) + } + + /// Return the raw flags the environment was opened with. + pub fn raw_flags(&self) -> Result { + let mut flags = std::mem::MaybeUninit::uninit(); + unsafe { mdb_result(ffi::mdb_env_get_flags(self.env_mut_ptr(), flags.as_mut_ptr()))? }; + let flags = unsafe { flags.assume_init() }; + + Ok(flags) + } + + /// Returns some basic informations about this environment. + pub fn info(&self) -> EnvInfo { + let mut raw_info = mem::MaybeUninit::uninit(); + unsafe { ffi::mdb_env_info(self.0.env, raw_info.as_mut_ptr()) }; + let raw_info = unsafe { raw_info.assume_init() }; + + EnvInfo { + map_addr: raw_info.me_mapaddr, + map_size: raw_info.me_mapsize, + last_page_number: raw_info.me_last_pgno, + last_txn_id: raw_info.me_last_txnid, + maximum_number_of_readers: raw_info.me_maxreaders, + number_of_readers: raw_info.me_numreaders, + } + } + + /// Returns the size used by all the databases in the environment without the free pages. + pub fn non_free_pages_size(&self) -> Result { + let compute_size = |stat: ffi::MDB_stat| { + (stat.ms_leaf_pages + stat.ms_branch_pages + stat.ms_overflow_pages) as u64 + * stat.ms_psize as u64 + }; + + let mut size = 0; + + let mut stat = std::mem::MaybeUninit::uninit(); + unsafe { mdb_result(ffi::mdb_env_stat(self.env_mut_ptr(), stat.as_mut_ptr()))? }; + let stat = unsafe { stat.assume_init() }; + size += compute_size(stat); + + let rtxn = self.read_txn()?; + let dbi = self.raw_open_dbi(rtxn.txn, None, 0)?; + + // we don’t want anyone to open an environment while we’re computing the stats + // thus we take a lock on the dbi + let dbi_open = self.0.dbi_open_mutex.lock().unwrap(); + + // We’re going to iterate on the unnamed database + let mut cursor = RoCursor::new(&rtxn, dbi)?; + + while let Some((key, _value)) = cursor.move_on_next()? { + if key.contains(&0) { + continue; + } + + let key = String::from_utf8(key.to_vec()).unwrap(); + if let Ok(dbi) = self.raw_open_dbi(rtxn.txn, Some(&key), 0) { + let mut stat = std::mem::MaybeUninit::uninit(); + unsafe { mdb_result(ffi::mdb_stat(rtxn.txn, dbi, stat.as_mut_ptr()))? }; + let stat = unsafe { stat.assume_init() }; + + size += compute_size(stat); + + // if the db wasn’t already opened + if !dbi_open.contains_key(&dbi) { + unsafe { ffi::mdb_dbi_close(self.env_mut_ptr(), dbi) } + } + } + } + + Ok(size) + } + /// Opens a typed database that already exists in this environment. /// /// If the database was previously opened in this program run, types will be checked. @@ -372,13 +495,12 @@ impl Env { } } - fn raw_init_database( + fn raw_open_dbi( &self, raw_txn: *mut ffi::MDB_txn, name: Option<&str>, - types: Option<(TypeId, TypeId)>, - create: bool, - ) -> Result { + flags: u32, + ) -> std::result::Result { let mut dbi = 0; let name = name.map(|n| CString::new(n).unwrap()); let name_ptr = match name { @@ -386,22 +508,25 @@ impl Env { None => ptr::null(), }; - let mut lock = self.0.dbi_open_mutex.lock().unwrap(); // safety: The name cstring is cloned by LMDB, we can drop it after. // If a read-only is used with the MDB_CREATE flag, LMDB will throw an error. - let result = unsafe { - mdb_result(ffi::mdb_dbi_open( - raw_txn, - name_ptr, - if create { ffi::MDB_CREATE } else { 0 }, - &mut dbi, - )) - }; + unsafe { mdb_result(ffi::mdb_dbi_open(raw_txn, name_ptr, flags, &mut dbi))? }; - drop(name); + Ok(dbi) + } + + fn raw_init_database( + &self, + raw_txn: *mut ffi::MDB_txn, + name: Option<&str>, + types: Option<(TypeId, TypeId)>, + create: bool, + ) -> Result { + let mut lock = self.0.dbi_open_mutex.lock().unwrap(); - match result { - Ok(()) => { + let flags = if create { ffi::MDB_CREATE } else { 0 }; + match self.raw_open_dbi(raw_txn, name, flags) { + Ok(dbi) => { let old_types = lock.entry(dbi).or_insert(types); if *old_types == types { Ok(dbi) @@ -430,9 +555,7 @@ impl Env { let file = File::options().create_new(true).write(true).open(&path)?; let fd = get_file_fd(&file); - unsafe { - self.copy_to_fd(fd, option)?; - } + unsafe { self.copy_to_fd(fd, option)? }; // We reopen the file to make sure the cursor is at the start, // even a seek to start doesn't work properly. @@ -447,9 +570,7 @@ impl Env { option: CompactionOption, ) -> Result<()> { let flags = if let CompactionOption::Enabled = option { ffi::MDB_CP_COMPACT } else { 0 }; - - mdb_result(ffi::mdb_env_copy2fd(self.0.env, fd, flags))?; - + mdb_result(ffi::mdb_env_copyfd2(self.0.env, fd, flags))?; Ok(()) } @@ -464,22 +585,6 @@ impl Env { &self.0.path } - /// Returns some basic informations about this environment. - pub fn info(&self) -> EnvInfo { - let mut raw_info = mem::MaybeUninit::uninit(); - unsafe { ffi::mdb_env_info(self.0.env, raw_info.as_mut_ptr()) }; - let raw_info = unsafe { raw_info.assume_init() }; - - EnvInfo { - map_addr: raw_info.me_mapaddr, - map_size: raw_info.me_mapsize, - last_page_number: raw_info.me_last_pgno, - last_txn_id: raw_info.me_last_txnid, - maximum_number_of_readers: raw_info.me_maxreaders, - number_of_readers: raw_info.me_numreaders, - } - } - /// Returns an `EnvClosingEvent` that can be used to wait for the closing event, /// multiple threads can wait on this event. /// diff --git a/heed/src/lib.rs b/heed/src/lib.rs index fe17c750..64af1a9e 100644 --- a/heed/src/lib.rs +++ b/heed/src/lib.rs @@ -11,8 +11,8 @@ //! //! # Examples //! -//! Discern let you open a database, that will support some typed key/data -//! and ensures, at compile time, that you'll write those types and not others. +//! Open a database, that will support some typed key/data and ensures, at compile time, +//! that you'll write those types and not others. //! //! ``` //! use std::fs; diff --git a/heed/src/mdb/lmdb_ffi.rs b/heed/src/mdb/lmdb_ffi.rs index e2b07993..d955f1d2 100644 --- a/heed/src/mdb/lmdb_ffi.rs +++ b/heed/src/mdb/lmdb_ffi.rs @@ -2,12 +2,12 @@ use std::ptr; pub use ffi::{ mdb_cursor_close, mdb_cursor_del, mdb_cursor_get, mdb_cursor_open, mdb_cursor_put, - mdb_dbi_open, mdb_del, mdb_drop, mdb_env_close, mdb_env_copyfd2 as mdb_env_copy2fd, - mdb_env_create, mdb_env_info, mdb_env_open, mdb_env_set_mapsize, mdb_env_set_maxdbs, - mdb_env_set_maxreaders, mdb_env_stat, mdb_env_sync, mdb_filehandle_t, mdb_get, mdb_put, - mdb_reader_check, mdb_stat, mdb_txn_abort, mdb_txn_begin, mdb_txn_commit, MDB_cursor, MDB_dbi, - MDB_env, MDB_envinfo, MDB_stat as MDB_Stat, MDB_txn, MDB_val, MDB_APPEND, MDB_CP_COMPACT, - MDB_CREATE, MDB_CURRENT, MDB_RDONLY, MDB_RESERVE, + mdb_dbi_close, mdb_dbi_open, mdb_del, mdb_drop, mdb_env_close, mdb_env_copyfd2, mdb_env_create, + mdb_env_get_fd, mdb_env_get_flags, mdb_env_info, mdb_env_open, mdb_env_set_mapsize, + mdb_env_set_maxdbs, mdb_env_set_maxreaders, mdb_env_stat, mdb_env_sync, mdb_filehandle_t, + mdb_get, mdb_put, mdb_reader_check, mdb_stat, mdb_txn_abort, mdb_txn_begin, mdb_txn_commit, + MDB_cursor, MDB_dbi, MDB_env, MDB_envinfo, MDB_stat, MDB_txn, MDB_val, MDB_APPEND, + MDB_CP_COMPACT, MDB_CREATE, MDB_CURRENT, MDB_RDONLY, MDB_RESERVE, }; use lmdb_master3_sys as ffi; From ec3e025e7fe8143d5039924c700cb485212a8a33 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Thu, 22 Sep 2022 15:28:31 +0200 Subject: [PATCH 28/57] Rename and document the copy_to_file function --- heed/src/env.rs | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/heed/src/env.rs b/heed/src/env.rs index fae9a7c7..75b1d292 100644 --- a/heed/src/env.rs +++ b/heed/src/env.rs @@ -289,9 +289,16 @@ impl Drop for EnvInner { } } +/// Whether to perform compaction while copying an environment. #[derive(Debug, Copy, Clone)] pub enum CompactionOption { + /// Omit free pages and sequentially renumber all pages in output. + /// + /// This option consumes more CPU and runs more slowly than the default. + /// Currently it fails if the environment has suffered a page leak. Enabled, + + /// Copy everything without taking any special action about free pages. Disabled, } @@ -390,7 +397,6 @@ impl Env { let mut stat = std::mem::MaybeUninit::uninit(); unsafe { mdb_result(ffi::mdb_stat(rtxn.txn, dbi, stat.as_mut_ptr()))? }; let stat = unsafe { stat.assume_init() }; - size += compute_size(stat); // if the db wasn’t already opened @@ -550,8 +556,11 @@ impl Env { RoTxn::new(self) } - // TODO rename into `copy_to_file` for more clarity - pub fn copy_to_path>(&self, path: P, option: CompactionOption) -> Result { + /// Copy an LMDB environment to the specified path, with options. + /// + /// This function may be used to make a backup of an existing environment. + /// No lockfile is created, since it gets recreated at need. + pub fn copy_to_file>(&self, path: P, option: CompactionOption) -> Result { let file = File::options().create_new(true).write(true).open(&path)?; let fd = get_file_fd(&file); @@ -564,6 +573,10 @@ impl Env { Ok(file) } + /// Copy an LMDB environment to the specified file descriptor, with compaction option. + /// + /// This function may be used to make a backup of an existing environment. + /// No lockfile is created, since it gets recreated at need. pub unsafe fn copy_to_fd( &self, fd: ffi::mdb_filehandle_t, @@ -576,7 +589,6 @@ impl Env { pub fn force_sync(&self) -> Result<()> { unsafe { mdb_result(ffi::mdb_env_sync(self.0.env, 1))? } - Ok(()) } @@ -592,9 +604,7 @@ impl Env { /// when all references are dropped, the last one will eventually close the environment. pub fn prepare_for_closing(self) -> EnvClosingEvent { let mut lock = OPENED_ENV.write().unwrap(); - let env = lock.get_mut(&self.0.path); - - match env { + match lock.get_mut(self.path()) { None => panic!("cannot find the env that we are trying to close"), Some(EnvEntry { env, signal_event, .. }) => { // We remove the env from the global list and replace it with a None. From 8f80c416e5cff9be887c927cf1aff2e66881dbb4 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Thu, 22 Sep 2022 16:25:53 +0200 Subject: [PATCH 29/57] A documentation to all the types at the root-level --- heed-traits/src/lib.rs | 2 ++ heed/src/env.rs | 27 ++++++++++++++---- heed/src/iter/iter.rs | 4 +++ heed/src/iter/prefix.rs | 4 +++ heed/src/iter/range.rs | 4 +++ heed/src/lib.rs | 6 ++-- heed/src/mdb/lmdb_flags.rs | 2 +- heed/src/txn.rs | 2 ++ .../tests/fixtures/testdb/data.mdb | Bin 180224 -> 180224 bytes .../tests/fixtures/testdb/lock.mdb | Bin 8128 -> 8128 bytes 10 files changed, 43 insertions(+), 8 deletions(-) diff --git a/heed-traits/src/lib.rs b/heed-traits/src/lib.rs index 66c883db..f1eb67a4 100644 --- a/heed-traits/src/lib.rs +++ b/heed-traits/src/lib.rs @@ -4,12 +4,14 @@ use std::error::Error as StdError; /// A boxed `Send + Sync + 'static` error. pub type BoxedError = Box; +/// A trait that represents an encoding structure. pub trait BytesEncode<'a> { type EItem: ?Sized + 'a; fn bytes_encode(item: &'a Self::EItem) -> Result, BoxedError>; } +/// A trait that represents a decoding structure. pub trait BytesDecode<'a> { type DItem: 'a; diff --git a/heed/src/env.rs b/heed/src/env.rs index 75b1d292..e3fe5859 100644 --- a/heed/src/env.rs +++ b/heed/src/env.rs @@ -20,10 +20,9 @@ use std::{io, mem, ptr, sync}; use once_cell::sync::Lazy; use synchronoise::event::SignalEvent; -use crate::flags::Flags; use crate::mdb::error::mdb_result; use crate::mdb::ffi; -use crate::{Database, Error, PolyDatabase, Result, RoCursor, RoTxn, RwTxn}; +use crate::{Database, Error, Flags, PolyDatabase, Result, RoCursor, RoTxn, RwTxn}; /// The list of opened environments, the value is an optional environment, it is None /// when someone asks to close the environment, closing is a two-phase step, to make sure @@ -93,6 +92,7 @@ unsafe fn metadata_from_fd(raw_fd: RawHandle) -> io::Result { File::from(owned).metadata() } +/// Options and flags which can be used to configure how an environment is opened. #[derive(Clone, Debug, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct EnvOpenOptions { @@ -103,20 +103,24 @@ pub struct EnvOpenOptions { } impl EnvOpenOptions { + /// Creates a blank new set of options ready for configuration. pub fn new() -> EnvOpenOptions { EnvOpenOptions { map_size: None, max_readers: None, max_dbs: None, flags: 0 } } + /// Set the size of the memory map to use for this environment. pub fn map_size(&mut self, size: usize) -> &mut Self { self.map_size = Some(size); self } + /// Set the maximum number of threads/reader slots for the environment. pub fn max_readers(&mut self, readers: u32) -> &mut Self { self.max_readers = Some(readers); self } + /// Set the maximum number of named databases for the environment. pub fn max_dbs(&mut self, dbs: u32) -> &mut Self { self.max_dbs = Some(dbs); self @@ -126,9 +130,8 @@ impl EnvOpenOptions { /// ``` /// use std::fs; /// use std::path::Path; - /// use heed::{EnvOpenOptions, Database}; + /// use heed::{EnvOpenOptions, Database, Flags}; /// use heed::types::*; - /// use heed::flags::Flags; /// /// # fn main() -> Result<(), Box> { /// fs::create_dir_all(Path::new("target").join("database.mdb"))?; @@ -170,6 +173,7 @@ impl EnvOpenOptions { self } + /// Open an environment that will be located at the specified path. pub fn open>(&self, path: P) -> Result { let path = canonicalize_path(path.as_ref())?; @@ -259,6 +263,7 @@ pub fn env_closing_event>(path: P) -> Option { lock.get(path.as_ref()).map(|e| EnvClosingEvent(e.signal_event.clone())) } +/// An environment handle constructed by using [`EnvOpenOptions`]. #[derive(Clone)] pub struct Env(Arc); @@ -544,14 +549,23 @@ impl Env { } } + /// Create a transaction with read and write access for use with the environment. pub fn write_txn(&self) -> Result { RwTxn::new(self) } + /// Create a nested transaction with read and write access for use with the environment. + /// + /// The new transaction will be a nested transaction, with the transaction indicated by parent + /// as its parent. Transactions may be nested to any level. + /// + /// A parent transaction and its cursors may not issue any other operations than _commit_ and + /// _abort_ while it has active child transactions. pub fn nested_write_txn<'e, 'p: 'e>(&'e self, parent: &'p mut RwTxn) -> Result> { RwTxn::nested(self, parent) } + /// Create a transaction with read only access for use with the environment. pub fn read_txn(&self) -> Result { RoTxn::new(self) } @@ -587,6 +601,7 @@ impl Env { Ok(()) } + /// Flush the data buffers to disk. pub fn force_sync(&self) -> Result<()> { unsafe { mdb_result(ffi::mdb_env_sync(self.0.env, 1))? } Ok(()) @@ -650,6 +665,8 @@ pub struct EnvInfo { pub number_of_readers: u32, } +/// A structure that can be used to wait for the closing event, +/// multiple threads can wait on this event. #[derive(Clone)] pub struct EnvClosingEvent(Arc); @@ -760,7 +777,7 @@ mod tests { let mut envbuilder = EnvOpenOptions::new(); envbuilder.map_size(10 * 1024 * 1024); // 10MB envbuilder.max_dbs(10); - unsafe { envbuilder.flag(crate::flags::Flags::MdbWriteMap) }; + unsafe { envbuilder.flag(crate::Flags::MdbWriteMap) }; let env = envbuilder.open(&dir.path()).unwrap(); let mut wtxn = env.write_txn().unwrap(); diff --git a/heed/src/iter/iter.rs b/heed/src/iter/iter.rs index d5af37b1..1e2814ca 100644 --- a/heed/src/iter/iter.rs +++ b/heed/src/iter/iter.rs @@ -3,6 +3,7 @@ use std::marker; use crate::*; +/// A read-only iterator structure. pub struct RoIter<'txn, KC, DC> { cursor: RoCursor<'txn>, move_on_first: bool, @@ -88,6 +89,7 @@ where } } +/// A read-write iterator structure. pub struct RwIter<'txn, KC, DC> { cursor: RwCursor<'txn>, move_on_first: bool, @@ -282,6 +284,7 @@ where } } +/// A reverse read-only iterator structure. pub struct RoRevIter<'txn, KC, DC> { cursor: RoCursor<'txn>, move_on_last: bool, @@ -367,6 +370,7 @@ where } } +/// A reverse read-write iterator structure. pub struct RwRevIter<'txn, KC, DC> { cursor: RwCursor<'txn>, move_on_last: bool, diff --git a/heed/src/iter/prefix.rs b/heed/src/iter/prefix.rs index d2d84628..7d36922a 100644 --- a/heed/src/iter/prefix.rs +++ b/heed/src/iter/prefix.rs @@ -15,6 +15,7 @@ fn move_on_prefix_end<'txn>( result } +/// A read-only prefix iterator structure. pub struct RoPrefix<'txn, KC, DC> { cursor: RoCursor<'txn>, prefix: Vec, @@ -114,6 +115,7 @@ where } } +/// A read-write prefix iterator structure. pub struct RwPrefix<'txn, KC, DC> { cursor: RwCursor<'txn>, prefix: Vec, @@ -322,6 +324,7 @@ where } } +/// A reverse read-only prefix iterator structure. pub struct RoRevPrefix<'txn, KC, DC> { cursor: RoCursor<'txn>, prefix: Vec, @@ -423,6 +426,7 @@ where } } +/// A reverse read-write prefix iterator structure. pub struct RwRevPrefix<'txn, KC, DC> { cursor: RwCursor<'txn>, prefix: Vec, diff --git a/heed/src/iter/range.rs b/heed/src/iter/range.rs index 196c464a..8d55783f 100644 --- a/heed/src/iter/range.rs +++ b/heed/src/iter/range.rs @@ -38,6 +38,7 @@ fn move_on_range_start<'txn>( } } +/// A read-only range iterator structure. pub struct RoRange<'txn, KC, DC> { cursor: RoCursor<'txn>, move_on_start: bool, @@ -161,6 +162,7 @@ where } } +/// A read-write range iterator structure. pub struct RwRange<'txn, KC, DC> { cursor: RwCursor<'txn>, move_on_start: bool, @@ -393,6 +395,7 @@ where } } +/// A reverse read-only range iterator structure. pub struct RoRevRange<'txn, KC, DC> { cursor: RoCursor<'txn>, move_on_end: bool, @@ -518,6 +521,7 @@ where } } +/// A reverse read-write range iterator structure. pub struct RwRevRange<'txn, KC, DC> { cursor: RwCursor<'txn>, move_on_end: bool, diff --git a/heed/src/lib.rs b/heed/src/lib.rs index 64af1a9e..dca0fca3 100644 --- a/heed/src/lib.rs +++ b/heed/src/lib.rs @@ -71,7 +71,7 @@ pub use self::iter::{ pub use self::lazy_decode::{Lazy, LazyDecode}; pub use self::mdb::error::Error as MdbError; use self::mdb::ffi::{from_val, into_val}; -pub use self::mdb::flags; +pub use self::mdb::flags::Flags; pub use self::reserved_space::ReservedSpace; pub use self::traits::{BoxedError, BytesDecode, BytesEncode}; pub use self::txn::{RoTxn, RwTxn}; @@ -125,6 +125,7 @@ impl From for Error { } } +/// Either a success or an [`Error`]. pub type Result = result::Result; #[cfg(test)] @@ -140,7 +141,6 @@ mod tests { } } -#[macro_export] macro_rules! assert_matching_env_txn { ($database:ident, $txn:ident) => { assert!( @@ -149,3 +149,5 @@ macro_rules! assert_matching_env_txn { ); }; } + +pub(crate) use assert_matching_env_txn; diff --git a/heed/src/mdb/lmdb_flags.rs b/heed/src/mdb/lmdb_flags.rs index fb7a66b5..7b998bfd 100644 --- a/heed/src/mdb/lmdb_flags.rs +++ b/heed/src/mdb/lmdb_flags.rs @@ -1,6 +1,6 @@ use lmdb_master3_sys as ffi; -// LMDB flags (see for more details). +/// LMDB flags (see for more details). #[repr(u32)] pub enum Flags { MdbFixedmap = ffi::MDB_FIXEDMAP, diff --git a/heed/src/txn.rs b/heed/src/txn.rs index e42f8c7c..567ec6ba 100644 --- a/heed/src/txn.rs +++ b/heed/src/txn.rs @@ -5,6 +5,7 @@ use crate::mdb::error::mdb_result; use crate::mdb::ffi; use crate::{Env, Result}; +/// A read-only transaction. pub struct RoTxn<'e> { pub(crate) txn: *mut ffi::MDB_txn, env: &'e Env, @@ -60,6 +61,7 @@ fn abort_txn(txn: *mut ffi::MDB_txn) -> Result<()> { Ok(unsafe { ffi::mdb_txn_abort(txn) }) } +/// A read-write transaction. pub struct RwTxn<'e, 'p> { pub(crate) txn: RoTxn<'e>, _parent: marker::PhantomData<&'p mut ()>, diff --git a/lmdb-master3-sys/tests/fixtures/testdb/data.mdb b/lmdb-master3-sys/tests/fixtures/testdb/data.mdb index 9de4a10fb605133355dafb41a474bfc961c263ce..e762b2e8ebd5ab9632d93a9e3f84ba2d4081e1d8 100644 GIT binary patch delta 90 zcmZo@;BIK(-Vot1d4>bu#55&NRt5;*njGjLx^Z2Q{lpC%n;JL{Fmi6@Y&dK`{Y*Wh s4I}4PPR8%{(+)6lFmi6^Jis{Lo{@86qxkd#{~0Bwuh`F|v4rUW0Q@f<(*OVf delta 93 zcmZo@;BIK(-Vot1d4>bu#55&NCI$%LnjGjLx^Z2Q{lpC%n;JL{FtTmtY&dK`{Y*Wh v4I|rDPR8%{(+)6lOg~W1#IarA0OJh%={M?`G^Stp&&a{Zy8Y&VM)d;#cmp7G diff --git a/lmdb-master3-sys/tests/fixtures/testdb/lock.mdb b/lmdb-master3-sys/tests/fixtures/testdb/lock.mdb index 5c3da772cea684bc39ef06dd8cf83934049784af..2676e3f07850b0c2ba8d94763637bfcaa6e05d86 100644 GIT binary patch delta 54 zcmX?Lf52Yh-hub~m>9w}I2j;-5lX97XK%kdV~6I%M1_eCLd>eUj2jc<5 delta 54 zcmX?Lf52Yh-hub~m>9w}I2a&+5lS!k^EWZ Date: Fri, 23 Sep 2022 15:32:37 +0200 Subject: [PATCH 30/57] Introduce the Database::put_reserved method --- heed/src/db/uniform.rs | 48 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/heed/src/db/uniform.rs b/heed/src/db/uniform.rs index fe9790e7..b60369b2 100644 --- a/heed/src/db/uniform.rs +++ b/heed/src/db/uniform.rs @@ -1250,6 +1250,54 @@ impl Database { self.dyndb.put::(txn, key, data) } + /// Insert a key-value pair where the value can directly be written to disk. + /// + /// ``` + /// # use std::fs; + /// # use std::path::Path; + /// # use heed::EnvOpenOptions; + /// use std::io::Write; + /// use heed::Database; + /// use heed::types::*; + /// use heed::byteorder::BigEndian; + /// + /// # fn main() -> Result<(), Box> { + /// # let dir = tempfile::tempdir()?; + /// # let env = EnvOpenOptions::new() + /// # .map_size(10 * 1024 * 1024) // 10MB + /// # .max_dbs(3000) + /// # .open(dir.path())?; + /// type BEI32 = I32; + /// + /// let mut wtxn = env.write_txn()?; + /// let db = env.create_database::, Str>(&mut wtxn, Some("number-string"))?; + /// + /// # db.clear(&mut wtxn)?; + /// let value = "I am a long long long value"; + /// db.put_reserved(&mut wtxn, &BEI32::new(42), value.len(), |reserved| { + /// reserved.write_all(value.as_bytes()) + /// })?; + /// + /// let ret = db.get(&mut wtxn, &BEI32::new(42))?; + /// assert_eq!(ret, Some(value)); + /// + /// wtxn.commit()?; + /// # Ok(()) } + /// ``` + pub fn put_reserved<'a, F>( + &self, + txn: &mut RwTxn, + key: &'a KC::EItem, + data_size: usize, + write_func: F, + ) -> Result<()> + where + KC: BytesEncode<'a>, + F: FnMut(&mut ReservedSpace) -> io::Result<()>, + { + self.dyndb.put_reserved::(txn, key, data_size, write_func) + } + /// Append the given key/data pair to the end of the database. /// /// This option allows fast bulk loading when keys are already known to be in the correct order. From 23aa2d863df7705f574ca617bf9ef9b9a73e51a6 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Sat, 29 Oct 2022 13:41:18 +0200 Subject: [PATCH 31/57] Implement Debug for Env --- heed/src/env.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/heed/src/env.rs b/heed/src/env.rs index e3fe5859..3129d16e 100644 --- a/heed/src/env.rs +++ b/heed/src/env.rs @@ -15,7 +15,7 @@ use std::{ ffi::OsStr, os::windows::io::{AsRawHandle, BorrowedHandle, RawHandle}, }; -use std::{io, mem, ptr, sync}; +use std::{fmt, io, mem, ptr, sync}; use once_cell::sync::Lazy; use synchronoise::event::SignalEvent; @@ -267,6 +267,13 @@ pub fn env_closing_event>(path: P) -> Option { #[derive(Clone)] pub struct Env(Arc); +impl fmt::Debug for Env { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let EnvInner { env: _, dbi_open_mutex: _, path } = self.0.as_ref(); + f.debug_struct("Env").field("path", &path.display()).finish_non_exhaustive() + } +} + struct EnvInner { env: *mut ffi::MDB_env, dbi_open_mutex: sync::Mutex>>, From e640e5c8739639ee2f87c9e1572a902a686e6ed1 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Sat, 29 Oct 2022 13:42:07 +0200 Subject: [PATCH 32/57] Return the original Env and the options when options differs --- heed/src/env.rs | 11 +++++++---- heed/src/lib.rs | 9 +++++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/heed/src/env.rs b/heed/src/env.rs index 3129d16e..228c338e 100644 --- a/heed/src/env.rs +++ b/heed/src/env.rs @@ -181,10 +181,13 @@ impl EnvOpenOptions { match lock.entry(path) { Entry::Occupied(entry) => { - if &entry.get().options != self { - return Err(Error::BadOpenOptions); + let env = entry.get().env.clone().ok_or(Error::DatabaseClosing)?; + let options = entry.get().options.clone(); + if &options == self { + return Ok(env); + } else { + return Err(Error::BadOpenOptions { env, options }); } - entry.get().env.clone().ok_or(Error::DatabaseClosing) } Entry::Vacant(entry) => { let path = entry.key(); @@ -759,7 +762,7 @@ mod tests { .map_size(12 * 1024 * 1024) // 12MB .open(&dir.path()); - assert!(matches!(result, Err(Error::BadOpenOptions))); + assert!(matches!(result, Err(Error::BadOpenOptions { .. }))); } #[test] diff --git a/heed/src/lib.rs b/heed/src/lib.rs index dca0fca3..cefb56f3 100644 --- a/heed/src/lib.rs +++ b/heed/src/lib.rs @@ -85,7 +85,12 @@ pub enum Error { Decoding(BoxedError), InvalidDatabaseTyping, DatabaseClosing, - BadOpenOptions, + BadOpenOptions { + /// The options that were used to originaly open this env. + options: EnvOpenOptions, + /// The env opened with the original options. + env: Env, + }, } impl fmt::Display for Error { @@ -101,7 +106,7 @@ impl fmt::Display for Error { Error::DatabaseClosing => { f.write_str("database is in a closing phase, you can't open it at the same time") } - Error::BadOpenOptions => { + Error::BadOpenOptions { .. } => { f.write_str("an environment is already opened with different options") } } From 906b23fa1fadc6e0f3fbb0f6a6d43bb67de847cf Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Sun, 30 Oct 2022 12:33:21 +0100 Subject: [PATCH 33/57] Introduce simpler integer codecs --- heed-types/src/integer.rs | 360 ++++-------------------- heed/examples/all-types-poly.rs | 23 +- heed/examples/all-types.rs | 21 +- heed/src/db/polymorph.rs | 479 +++++++++++++++---------------- heed/src/db/uniform.rs | 483 ++++++++++++++++---------------- heed/src/iter/mod.rs | 150 +++++----- 6 files changed, 629 insertions(+), 887 deletions(-) diff --git a/heed-types/src/integer.rs b/heed-types/src/integer.rs index 24e76410..214d39f2 100644 --- a/heed-types/src/integer.rs +++ b/heed-types/src/integer.rs @@ -1,337 +1,75 @@ -// Copyright 2019 The Fuchsia Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the Fushia_LICENSE file. - -//! Byte order-aware numeric primitives. -//! -//! This module contains equivalents of the native multi-byte integer types with -//! no alignment requirement and supporting byte order conversions. -//! -//! For each native multi-byte integer type - `u16`, `i16`, `u32`, etc - an -//! equivalent type is defined by this module - [`U16`], [`I16`], [`U32`], etc. -//! Unlike their native counterparts, these types have alignment 1, and take a -//! type parameter specifying the byte order in which the bytes are stored in -//! memory. Each type implements the [`Zeroable`], and [`Pod`] traits. -//! -//! These two properties, taken together, make these types very useful for -//! defining data structures whose memory layout matches a wire format such as -//! that of a network protocol or a file format. Such formats often have -//! multi-byte values at offsets that do not respect the alignment requirements -//! of the equivalent native types, and stored in a byte order not necessarily -//! the same as that of the target platform. - -use std::fmt::{self, Binary, Debug, Display, Formatter, LowerHex, Octal, UpperHex}; +use std::borrow::Cow; use std::marker::PhantomData; +use std::mem::size_of; -use bytemuck::{Pod, Zeroable}; -use byteorder::ByteOrder; - -macro_rules! impl_fmt_trait { - ($name:ident, $native:ident, $trait:ident) => { - impl $trait for $name { - fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { - $trait::fmt(&self.get(), f) - } - } - }; -} - -macro_rules! doc_comment { - ($x:expr, $($tt:tt)*) => { - #[doc = $x] - $($tt)* - }; -} - -macro_rules! define_type { - ($article:ident, $name:ident, $native:ident, $bits:expr, $bytes:expr, $read_method:ident, $write_method:ident, $sign:ident) => { - doc_comment! { - concat!("A ", stringify!($bits), "-bit ", stringify!($sign), " integer -stored in `O` byte order. - -`", stringify!($name), "` is like the native `", stringify!($native), "` type with -two major differences: First, it has no alignment requirement (its alignment is 1). -Second, the endianness of its memory layout is given by the type parameter `O`. - -", stringify!($article), " `", stringify!($name), "` can be constructed using -the [`new`] method, and its contained value can be obtained as a native -`",stringify!($native), "` using the [`get`] method, or updated in place with -the [`set`] method. In all cases, if the endianness `O` is not the same as the -endianness of the current platform, an endianness swap will be performed in -order to uphold the invariants that a) the layout of `", stringify!($name), "` -has endianness `O` and that, b) the layout of `", stringify!($native), "` has -the platform's native endianness. - -`", stringify!($name), "` implements [`Zeroable`], and [`Pod`], -making it useful for parsing and serialization. - -[`new`]: crate::integer::", stringify!($name), "::new -[`get`]: crate::integer::", stringify!($name), "::get -[`set`]: crate::integer::", stringify!($name), "::set -[`Zeroable`]: bytemuck::Zeroable -[`Pod`]: bytemuck::Pod"), - #[derive(Default, Copy, Clone, Eq, PartialEq, Hash)] - #[repr(transparent)] - pub struct $name([u8; $bytes], PhantomData); - } - - unsafe impl Zeroable for $name { - fn zeroed() -> $name { - $name([0u8; $bytes], PhantomData) - } - } - - unsafe impl Pod for $name {} - - impl $name { - // TODO(joshlf): Make these const fns if the ByteOrder methods ever - // become const fns. - - /// Constructs a new value, possibly performing an endianness swap - /// to guarantee that the returned value has endianness `O`. - pub fn new(n: $native) -> $name { - let mut out = $name::default(); - O::$write_method(&mut out.0[..], n); - out - } - - /// Returns the value as a primitive type, possibly performing an - /// endianness swap to guarantee that the return value has the - /// endianness of the native platform. - pub fn get(self) -> $native { - O::$read_method(&self.0[..]) - } - - /// Updates the value in place as a primitive type, possibly - /// performing an endianness swap to guarantee that the stored value - /// has the endianness `O`. - pub fn set(&mut self, n: $native) { - O::$write_method(&mut self.0[..], n); - } - } - - // NOTE: The reasoning behind which traits to implement here is a) only - // implement traits which do not involve implicit endianness swaps and, - // b) only implement traits which won't cause inference issues. Most of - // the traits which would cause inference issues would also involve - // endianness swaps anyway (like comparison/ordering with the native - // representation or conversion from/to that representation). Note that - // we make an exception for the format traits since the cost of - // formatting dwarfs cost of performing an endianness swap, and they're - // very useful. - - impl From<$name> for [u8; $bytes] { - fn from(x: $name) -> [u8; $bytes] { - x.0 - } - } - - impl From<[u8; $bytes]> for $name { - fn from(bytes: [u8; $bytes]) -> $name { - $name(bytes, PhantomData) - } - } - - impl AsRef<[u8; $bytes]> for $name { - fn as_ref(&self) -> &[u8; $bytes] { - &self.0 - } - } - - impl AsMut<[u8; $bytes]> for $name { - fn as_mut(&mut self) -> &mut [u8; $bytes] { - &mut self.0 - } - } - - impl PartialEq<$name> for [u8; $bytes] { - fn eq(&self, other: &$name) -> bool { - self.eq(&other.0) - } - } - - impl PartialEq<[u8; $bytes]> for $name { - fn eq(&self, other: &[u8; $bytes]) -> bool { - self.0.eq(other) - } - } - - impl_fmt_trait!($name, $native, Display); - impl_fmt_trait!($name, $native, Octal); - impl_fmt_trait!($name, $native, LowerHex); - impl_fmt_trait!($name, $native, UpperHex); - impl_fmt_trait!($name, $native, Binary); +use byteorder::{ByteOrder, ReadBytesExt}; +use heed_traits::{BoxedError, BytesDecode, BytesEncode}; - impl Debug for $name { - fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { - // This results in a format like "U16(42)" - write!(f, concat!(stringify!($name), "({})"), self.get()) - } - } - }; -} - -define_type!(A, U16, u16, 16, 2, read_u16, write_u16, unsigned); -define_type!(A, U32, u32, 32, 4, read_u32, write_u32, unsigned); -define_type!(A, U64, u64, 64, 8, read_u64, write_u64, unsigned); -define_type!(A, U128, u128, 128, 16, read_u128, write_u128, unsigned); -define_type!(An, I16, i16, 16, 2, read_i16, write_i16, signed); -define_type!(An, I32, i32, 32, 4, read_i32, write_i32, signed); -define_type!(An, I64, i64, 64, 8, read_i64, write_i64, signed); -define_type!(An, I128, i128, 128, 16, read_i128, write_i128, signed); +pub struct U8; -#[cfg(test)] -mod tests { - use bytemuck::{bytes_of, bytes_of_mut, Pod}; - use byteorder::NativeEndian; +impl BytesEncode<'_> for U8 { + type EItem = u8; - use super::*; - - // A native integer type (u16, i32, etc) - trait Native: Pod + Copy + Eq + Debug { - fn rand() -> Self; - } - - trait ByteArray: Pod + Copy + AsRef<[u8]> + AsMut<[u8]> + Debug + Default + Eq { - /// Invert the order of the bytes in the array. - fn invert(self) -> Self; + fn bytes_encode(item: &Self::EItem) -> Result, BoxedError> { + Ok(Cow::from([*item].to_vec())) } +} - trait ByteOrderType: Pod + Copy + Eq + Debug { - type Native: Native; - type ByteArray: ByteArray; +impl BytesDecode<'_> for U8 { + type DItem = u8; - fn new(native: Self::Native) -> Self; - fn get(self) -> Self::Native; - fn set(&mut self, native: Self::Native); - fn from_bytes(bytes: Self::ByteArray) -> Self; - fn into_bytes(self) -> Self::ByteArray; + fn bytes_decode(mut bytes: &'_ [u8]) -> Result { + bytes.read_u8().map_err(Into::into) } +} - macro_rules! impl_byte_array { - ($bytes:expr) => { - impl ByteArray for [u8; $bytes] { - fn invert(mut self) -> [u8; $bytes] { - self.reverse(); - self - } - } - }; - } - - impl_byte_array!(2); - impl_byte_array!(4); - impl_byte_array!(8); - impl_byte_array!(16); - - macro_rules! impl_traits { - ($name:ident, $native:ident, $bytes:expr, $sign:ident) => { - impl Native for $native { - fn rand() -> $native { - rand::random() - } - } - - impl ByteOrderType for $name { - type Native = $native; - type ByteArray = [u8; $bytes]; - - fn new(native: $native) -> $name { - $name::new(native) - } - - fn get(self) -> $native { - $name::get(self) - } - - fn set(&mut self, native: $native) { - $name::set(self, native) - } +pub struct I8; - fn from_bytes(bytes: [u8; $bytes]) -> $name { - $name::from(bytes) - } +impl BytesEncode<'_> for I8 { + type EItem = i8; - fn into_bytes(self) -> [u8; $bytes] { - <[u8; $bytes]>::from(self) - } - } - }; + fn bytes_encode(item: &Self::EItem) -> Result, BoxedError> { + Ok(Cow::from([*item as u8].to_vec())) } +} - impl_traits!(U16, u16, 2, unsigned); - impl_traits!(U32, u32, 4, unsigned); - impl_traits!(U64, u64, 8, unsigned); - impl_traits!(U128, u128, 16, unsigned); - impl_traits!(I16, i16, 2, signed); - impl_traits!(I32, i32, 4, signed); - impl_traits!(I64, i64, 8, signed); - impl_traits!(I128, i128, 16, signed); +impl BytesDecode<'_> for I8 { + type DItem = i8; - macro_rules! call_for_all_types { - ($fn:ident, $byteorder:ident) => { - $fn::>(); - $fn::>(); - $fn::>(); - $fn::>(); - $fn::>(); - $fn::>(); - $fn::>(); - $fn::>(); - }; + fn bytes_decode(mut bytes: &'_ [u8]) -> Result { + bytes.read_i8().map_err(Into::into) } +} - #[cfg(target_endian = "big")] - type NonNativeEndian = byteorder::LittleEndian; - #[cfg(target_endian = "little")] - type NonNativeEndian = byteorder::BigEndian; +macro_rules! define_type { + ($name:ident, $native:ident, $read_method:ident, $write_method:ident) => { + pub struct $name(PhantomData); - #[test] - fn test_native_endian() { - fn test_native_endian() { - for _ in 0..1024 { - let native = T::Native::rand(); - let mut bytes = T::ByteArray::default(); - bytes_of_mut(&mut bytes).copy_from_slice(bytes_of(&native)); - let mut from_native = T::new(native); - let from_bytes = T::from_bytes(bytes); - assert_eq!(from_native, from_bytes); - assert_eq!(from_native.get(), native); - assert_eq!(from_bytes.get(), native); - assert_eq!(from_native.into_bytes(), bytes); - assert_eq!(from_bytes.into_bytes(), bytes); + impl BytesEncode<'_> for $name { + type EItem = $native; - let updated = T::Native::rand(); - from_native.set(updated); - assert_eq!(from_native.get(), updated); + fn bytes_encode(item: &Self::EItem) -> Result, BoxedError> { + let mut buf = [0; size_of::()]; + O::$write_method(&mut buf, *item); + Ok(Cow::from(buf.to_vec())) } } - call_for_all_types!(test_native_endian, NativeEndian); - } - - #[test] - fn test_non_native_endian() { - fn test_non_native_endian() { - for _ in 0..1024 { - let native = T::Native::rand(); - let mut bytes = T::ByteArray::default(); - bytes_of_mut(&mut bytes).copy_from_slice(bytes_of(&native)); - bytes = bytes.invert(); - let mut from_native = T::new(native); - let from_bytes = T::from_bytes(bytes); - assert_eq!(from_native, from_bytes); - assert_eq!(from_native.get(), native); - assert_eq!(from_bytes.get(), native); - assert_eq!(from_native.into_bytes(), bytes); - assert_eq!(from_bytes.into_bytes(), bytes); + impl BytesDecode<'_> for $name { + type DItem = $native; - let updated = T::Native::rand(); - from_native.set(updated); - assert_eq!(from_native.get(), updated); + fn bytes_decode(mut bytes: &'_ [u8]) -> Result { + bytes.$read_method::().map_err(Into::into) } } - - call_for_all_types!(test_non_native_endian, NonNativeEndian); - } + }; } + +define_type!(U16, u16, read_u16, write_u16); +define_type!(U32, u32, read_u32, write_u32); +define_type!(U64, u64, read_u64, write_u64); +define_type!(U128, u128, read_u128, write_u128); +define_type!(I16, i16, read_i16, write_i16); +define_type!(I32, i32, read_i32, write_i32); +define_type!(I64, i64, read_i64, write_i64); +define_type!(I128, i128, read_i128, write_i128); diff --git a/heed/examples/all-types-poly.rs b/heed/examples/all-types-poly.rs index 1be6618d..61111c6c 100644 --- a/heed/examples/all-types-poly.rs +++ b/heed/examples/all-types-poly.rs @@ -107,7 +107,7 @@ fn main() -> Result<(), Box> { // NOTE that those types are not saved upon runs and // therefore types cannot be checked upon different runs, // the first database opening fix the types for this run. - let result = env.create_database::, Unit>(&mut wtxn, Some("ignored-data")); + let result = env.create_database::(&mut wtxn, Some("ignored-data")); assert!(result.is_err()); // you can iterate over keys in order @@ -115,27 +115,26 @@ fn main() -> Result<(), Box> { let db = env.create_poly_database(&mut wtxn, Some("big-endian-iter"))?; - db.put::, Unit>(&mut wtxn, &BEI64::new(0), &())?; - db.put::, Unit>(&mut wtxn, &BEI64::new(68), &())?; - db.put::, Unit>(&mut wtxn, &BEI64::new(35), &())?; - db.put::, Unit>(&mut wtxn, &BEI64::new(42), &())?; + db.put::(&mut wtxn, &0, &())?; + db.put::(&mut wtxn, &68, &())?; + db.put::(&mut wtxn, &35, &())?; + db.put::(&mut wtxn, &42, &())?; - let rets: Result, _> = db.iter::, Unit>(&wtxn)?.collect(); + let rets: Result, _> = db.iter::(&wtxn)?.collect(); println!("{:?}", rets); // or iterate over ranges too!!! - let range = BEI64::new(35)..=BEI64::new(42); - let rets: Result, _> = - db.range::, Unit, _>(&wtxn, &range)?.collect(); + let range = 35..=42; + let rets: Result, _> = db.range::(&wtxn, &range)?.collect(); println!("{:?}", rets); // delete a range of key - let range = BEI64::new(35)..=BEI64::new(42); - let deleted: usize = db.delete_range::, _>(&mut wtxn, &range)?; + let range = 35..=42; + let deleted: usize = db.delete_range::(&mut wtxn, &range)?; - let rets: Result, _> = db.iter::, Unit>(&wtxn)?.collect(); + let rets: Result, _> = db.iter::(&wtxn)?.collect(); println!("deleted: {:?}, {:?}", deleted, rets); wtxn.commit()?; diff --git a/heed/examples/all-types.rs b/heed/examples/all-types.rs index a4895eaf..e7a1c709 100644 --- a/heed/examples/all-types.rs +++ b/heed/examples/all-types.rs @@ -121,29 +121,28 @@ fn main() -> Result<(), Box> { // you can iterate over keys in order type BEI64 = I64; - let db: Database, Unit> = - env.create_database(&mut wtxn, Some("big-endian-iter"))?; + let db: Database = env.create_database(&mut wtxn, Some("big-endian-iter"))?; - let _ret = db.put(&mut wtxn, &BEI64::new(0), &())?; - let _ret = db.put(&mut wtxn, &BEI64::new(68), &())?; - let _ret = db.put(&mut wtxn, &BEI64::new(35), &())?; - let _ret = db.put(&mut wtxn, &BEI64::new(42), &())?; + let _ret = db.put(&mut wtxn, &0, &())?; + let _ret = db.put(&mut wtxn, &68, &())?; + let _ret = db.put(&mut wtxn, &35, &())?; + let _ret = db.put(&mut wtxn, &42, &())?; - let rets: Result, _> = db.iter(&wtxn)?.collect(); + let rets: Result, _> = db.iter(&wtxn)?.collect(); println!("{:?}", rets); // or iterate over ranges too!!! - let range = BEI64::new(35)..=BEI64::new(42); - let rets: Result, _> = db.range(&wtxn, &range)?.collect(); + let range = 35..=42; + let rets: Result, _> = db.range(&wtxn, &range)?.collect(); println!("{:?}", rets); // delete a range of key - let range = BEI64::new(35)..=BEI64::new(42); + let range = 35..=42; let deleted: usize = db.delete_range(&mut wtxn, &range)?; - let rets: Result, _> = db.iter(&wtxn)?.collect(); + let rets: Result, _> = db.iter(&wtxn)?.collect(); println!("deleted: {:?}, {:?}", deleted, rets); wtxn.commit()?; diff --git a/heed/src/db/polymorph.rs b/heed/src/db/polymorph.rs index 499325a0..b8a032c2 100644 --- a/heed/src/db/polymorph.rs +++ b/heed/src/db/polymorph.rs @@ -35,16 +35,16 @@ use crate::*; /// let db: PolyDatabase = env.create_poly_database(&mut wtxn, Some("big-endian-iter"))?; /// /// # db.clear(&mut wtxn)?; -/// db.put::, Unit>(&mut wtxn, &BEI64::new(0), &())?; -/// db.put::, Str>(&mut wtxn, &BEI64::new(35), "thirty five")?; -/// db.put::, Str>(&mut wtxn, &BEI64::new(42), "forty two")?; -/// db.put::, Unit>(&mut wtxn, &BEI64::new(68), &())?; +/// db.put::(&mut wtxn, &0, &())?; +/// db.put::(&mut wtxn, &35, "thirty five")?; +/// db.put::(&mut wtxn, &42, "forty two")?; +/// db.put::(&mut wtxn, &68, &())?; /// /// // you can iterate over database entries in order -/// let range = BEI64::new(35)..=BEI64::new(42); -/// let mut range = db.range::, Str, _>(&wtxn, &range)?; -/// assert_eq!(range.next().transpose()?, Some((BEI64::new(35), "thirty five"))); -/// assert_eq!(range.next().transpose()?, Some((BEI64::new(42), "forty two"))); +/// let range = 35..=42; +/// let mut range = db.range::(&wtxn, &range)?; +/// assert_eq!(range.next().transpose()?, Some((35, "thirty five"))); +/// assert_eq!(range.next().transpose()?, Some((42, "forty two"))); /// assert_eq!(range.next().transpose()?, None); /// /// drop(range); @@ -78,22 +78,22 @@ use crate::*; /// let db: PolyDatabase = env.create_poly_database(&mut wtxn, Some("big-endian-iter"))?; /// /// # db.clear(&mut wtxn)?; -/// db.put::, Unit>(&mut wtxn, &BEI64::new(0), &())?; -/// db.put::, Str>(&mut wtxn, &BEI64::new(35), "thirty five")?; -/// db.put::, Str>(&mut wtxn, &BEI64::new(42), "forty two")?; -/// db.put::, Unit>(&mut wtxn, &BEI64::new(68), &())?; +/// db.put::(&mut wtxn, &0, &())?; +/// db.put::(&mut wtxn, &35, "thirty five")?; +/// db.put::(&mut wtxn, &42, "forty two")?; +/// db.put::(&mut wtxn, &68, &())?; /// /// // even delete a range of keys -/// let range = BEI64::new(35)..=BEI64::new(42); -/// let deleted = db.delete_range::, _>(&mut wtxn, &range)?; +/// let range = 35..=42; +/// let deleted = db.delete_range::(&mut wtxn, &range)?; /// assert_eq!(deleted, 2); /// -/// let rets: Result<_, _> = db.iter::, Unit>(&wtxn)?.collect(); -/// let rets: Vec<(BEI64, _)> = rets?; +/// let rets: Result<_, _> = db.iter::(&wtxn)?.collect(); +/// let rets: Vec<(i64, _)> = rets?; /// /// let expected = vec![ -/// (BEI64::new(0), ()), -/// (BEI64::new(68), ()), +/// (0, ()), +/// (68, ()), /// ]; /// /// assert_eq!(deleted, 2); @@ -123,6 +123,7 @@ impl PolyDatabase { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -130,17 +131,19 @@ impl PolyDatabase { /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) /// # .open(dir.path())?; + /// type BEI32 = I32; + /// /// let mut wtxn = env.write_txn()?; /// let db = env.create_poly_database(&mut wtxn, Some("get-poly-i32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put::>(&mut wtxn, "i-am-forty-two", &42)?; - /// db.put::>(&mut wtxn, "i-am-twenty-seven", &27)?; + /// db.put::(&mut wtxn, "i-am-forty-two", &42)?; + /// db.put::(&mut wtxn, "i-am-twenty-seven", &27)?; /// - /// let ret = db.get::>(&wtxn, "i-am-forty-two")?; + /// let ret = db.get::(&wtxn, "i-am-forty-two")?; /// assert_eq!(ret, Some(42)); /// - /// let ret = db.get::>(&wtxn, "i-am-twenty-one")?; + /// let ret = db.get::(&wtxn, "i-am-twenty-one")?; /// assert_eq!(ret, None); /// /// wtxn.commit()?; @@ -204,17 +207,17 @@ impl PolyDatabase { /// let db = env.create_poly_database(&mut wtxn, Some("get-lt-u32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put::, Unit>(&mut wtxn, &BEU32::new(27), &())?; - /// db.put::, Unit>(&mut wtxn, &BEU32::new(42), &())?; - /// db.put::, Unit>(&mut wtxn, &BEU32::new(43), &())?; + /// db.put::(&mut wtxn, &27, &())?; + /// db.put::(&mut wtxn, &42, &())?; + /// db.put::(&mut wtxn, &43, &())?; /// - /// let ret = db.get_lower_than::, Unit>(&wtxn, &BEU32::new(4404))?; - /// assert_eq!(ret, Some((BEU32::new(43), ()))); + /// let ret = db.get_lower_than::(&wtxn, &4404)?; + /// assert_eq!(ret, Some((43, ()))); /// - /// let ret = db.get_lower_than::, Unit>(&wtxn, &BEU32::new(43))?; - /// assert_eq!(ret, Some((BEU32::new(42), ()))); + /// let ret = db.get_lower_than::(&wtxn, &43)?; + /// assert_eq!(ret, Some((42, ()))); /// - /// let ret = db.get_lower_than::, Unit>(&wtxn, &BEU32::new(27))?; + /// let ret = db.get_lower_than::(&wtxn, &27)?; /// assert_eq!(ret, None); /// /// wtxn.commit()?; @@ -272,17 +275,17 @@ impl PolyDatabase { /// let db = env.create_poly_database(&mut wtxn, Some("get-lte-u32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put::, Unit>(&mut wtxn, &BEU32::new(27), &())?; - /// db.put::, Unit>(&mut wtxn, &BEU32::new(42), &())?; - /// db.put::, Unit>(&mut wtxn, &BEU32::new(43), &())?; + /// db.put::(&mut wtxn, &27, &())?; + /// db.put::(&mut wtxn, &42, &())?; + /// db.put::(&mut wtxn, &43, &())?; /// - /// let ret = db.get_lower_than_or_equal_to::, Unit>(&wtxn, &BEU32::new(4404))?; - /// assert_eq!(ret, Some((BEU32::new(43), ()))); + /// let ret = db.get_lower_than_or_equal_to::(&wtxn, &4404)?; + /// assert_eq!(ret, Some((43, ()))); /// - /// let ret = db.get_lower_than_or_equal_to::, Unit>(&wtxn, &BEU32::new(43))?; - /// assert_eq!(ret, Some((BEU32::new(43), ()))); + /// let ret = db.get_lower_than_or_equal_to::(&wtxn, &43)?; + /// assert_eq!(ret, Some((43, ()))); /// - /// let ret = db.get_lower_than_or_equal_to::, Unit>(&wtxn, &BEU32::new(26))?; + /// let ret = db.get_lower_than_or_equal_to::(&wtxn, &26)?; /// assert_eq!(ret, None); /// /// wtxn.commit()?; @@ -344,17 +347,17 @@ impl PolyDatabase { /// let db = env.create_poly_database(&mut wtxn, Some("get-lt-u32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put::, Unit>(&mut wtxn, &BEU32::new(27), &())?; - /// db.put::, Unit>(&mut wtxn, &BEU32::new(42), &())?; - /// db.put::, Unit>(&mut wtxn, &BEU32::new(43), &())?; + /// db.put::(&mut wtxn, &27, &())?; + /// db.put::(&mut wtxn, &42, &())?; + /// db.put::(&mut wtxn, &43, &())?; /// - /// let ret = db.get_greater_than::, Unit>(&wtxn, &BEU32::new(0))?; - /// assert_eq!(ret, Some((BEU32::new(27), ()))); + /// let ret = db.get_greater_than::(&wtxn, &0)?; + /// assert_eq!(ret, Some((27, ()))); /// - /// let ret = db.get_greater_than::, Unit>(&wtxn, &BEU32::new(42))?; - /// assert_eq!(ret, Some((BEU32::new(43), ()))); + /// let ret = db.get_greater_than::(&wtxn, &42)?; + /// assert_eq!(ret, Some((43, ()))); /// - /// let ret = db.get_greater_than::, Unit>(&wtxn, &BEU32::new(43))?; + /// let ret = db.get_greater_than::(&wtxn, &43)?; /// assert_eq!(ret, None); /// /// wtxn.commit()?; @@ -415,17 +418,17 @@ impl PolyDatabase { /// let db = env.create_poly_database(&mut wtxn, Some("get-lt-u32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put::, Unit>(&mut wtxn, &BEU32::new(27), &())?; - /// db.put::, Unit>(&mut wtxn, &BEU32::new(42), &())?; - /// db.put::, Unit>(&mut wtxn, &BEU32::new(43), &())?; + /// db.put::(&mut wtxn, &27, &())?; + /// db.put::(&mut wtxn, &42, &())?; + /// db.put::(&mut wtxn, &43, &())?; /// - /// let ret = db.get_greater_than_or_equal_to::, Unit>(&wtxn, &BEU32::new(0))?; - /// assert_eq!(ret, Some((BEU32::new(27), ()))); + /// let ret = db.get_greater_than_or_equal_to::(&wtxn, &0)?; + /// assert_eq!(ret, Some((27, ()))); /// - /// let ret = db.get_greater_than_or_equal_to::, Unit>(&wtxn, &BEU32::new(42))?; - /// assert_eq!(ret, Some((BEU32::new(42), ()))); + /// let ret = db.get_greater_than_or_equal_to::(&wtxn, &42)?; + /// assert_eq!(ret, Some((42, ()))); /// - /// let ret = db.get_greater_than_or_equal_to::, Unit>(&wtxn, &BEU32::new(44))?; + /// let ret = db.get_greater_than_or_equal_to::(&wtxn, &44)?; /// assert_eq!(ret, None); /// /// wtxn.commit()?; @@ -480,11 +483,11 @@ impl PolyDatabase { /// let db = env.create_poly_database(&mut wtxn, Some("first-poly-i32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; + /// db.put::(&mut wtxn, &42, "i-am-forty-two")?; + /// db.put::(&mut wtxn, &27, "i-am-twenty-seven")?; /// - /// let ret = db.first::, Str>(&wtxn)?; - /// assert_eq!(ret, Some((BEI32::new(27), "i-am-twenty-seven"))); + /// let ret = db.first::(&wtxn)?; + /// assert_eq!(ret, Some((27, "i-am-twenty-seven"))); /// /// wtxn.commit()?; /// # Ok(()) } @@ -533,11 +536,11 @@ impl PolyDatabase { /// let db = env.create_poly_database(&mut wtxn, Some("last-i32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; + /// db.put::(&mut wtxn, &42, "i-am-forty-two")?; + /// db.put::(&mut wtxn, &27, "i-am-twenty-seven")?; /// - /// let ret = db.last::, Str>(&wtxn)?; - /// assert_eq!(ret, Some((BEI32::new(42), "i-am-forty-two"))); + /// let ret = db.last::(&wtxn)?; + /// assert_eq!(ret, Some((42, "i-am-forty-two"))); /// /// wtxn.commit()?; /// # Ok(()) } @@ -582,15 +585,15 @@ impl PolyDatabase { /// let db = env.create_poly_database(&mut wtxn, Some("iter-i32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(521), "i-am-five-hundred-and-twenty-one")?; + /// db.put::(&mut wtxn, &42, "i-am-forty-two")?; + /// db.put::(&mut wtxn, &27, "i-am-twenty-seven")?; + /// db.put::(&mut wtxn, &13, "i-am-thirteen")?; + /// db.put::(&mut wtxn, &521, "i-am-five-hundred-and-twenty-one")?; /// /// let ret = db.len(&wtxn)?; /// assert_eq!(ret, 4); /// - /// db.delete::>(&mut wtxn, &BEI32::new(27))?; + /// db.delete::(&mut wtxn, &27)?; /// /// let ret = db.len(&wtxn)?; /// assert_eq!(ret, 3); @@ -636,10 +639,10 @@ impl PolyDatabase { /// let db = env.create_poly_database(&mut wtxn, Some("iter-i32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(521), "i-am-five-hundred-and-twenty-one")?; + /// db.put::(&mut wtxn, &42, "i-am-forty-two")?; + /// db.put::(&mut wtxn, &27, "i-am-twenty-seven")?; + /// db.put::(&mut wtxn, &13, "i-am-thirteen")?; + /// db.put::(&mut wtxn, &521, "i-am-five-hundred-and-twenty-one")?; /// /// let ret = db.is_empty(&wtxn)?; /// assert_eq!(ret, false); @@ -684,14 +687,14 @@ impl PolyDatabase { /// let db = env.create_poly_database(&mut wtxn, Some("iter-i32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; - /// - /// let mut iter = db.iter::, Str>(&wtxn)?; - /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(13), "i-am-thirteen"))); - /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(27), "i-am-twenty-seven"))); - /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(42), "i-am-forty-two"))); + /// db.put::(&mut wtxn, &42, "i-am-forty-two")?; + /// db.put::(&mut wtxn, &27, "i-am-twenty-seven")?; + /// db.put::(&mut wtxn, &13, "i-am-thirteen")?; + /// + /// let mut iter = db.iter::(&wtxn)?; + /// assert_eq!(iter.next().transpose()?, Some((13, "i-am-thirteen"))); + /// assert_eq!(iter.next().transpose()?, Some((27, "i-am-twenty-seven"))); + /// assert_eq!(iter.next().transpose()?, Some((42, "i-am-forty-two"))); /// assert_eq!(iter.next().transpose()?, None); /// /// drop(iter); @@ -726,28 +729,28 @@ impl PolyDatabase { /// let db = env.create_poly_database(&mut wtxn, Some("iter-i32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; + /// db.put::(&mut wtxn, &42, "i-am-forty-two")?; + /// db.put::(&mut wtxn, &27, "i-am-twenty-seven")?; + /// db.put::(&mut wtxn, &13, "i-am-thirteen")?; /// - /// let mut iter = db.iter_mut::, Str>(&mut wtxn)?; - /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(13), "i-am-thirteen"))); + /// let mut iter = db.iter_mut::(&mut wtxn)?; + /// assert_eq!(iter.next().transpose()?, Some((13, "i-am-thirteen"))); /// let ret = unsafe { iter.del_current()? }; /// assert!(ret); /// - /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(27), "i-am-twenty-seven"))); - /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(42), "i-am-forty-two"))); - /// let ret = unsafe { iter.put_current(&BEI32::new(42), "i-am-the-new-forty-two")? }; + /// assert_eq!(iter.next().transpose()?, Some((27, "i-am-twenty-seven"))); + /// assert_eq!(iter.next().transpose()?, Some((42, "i-am-forty-two"))); + /// let ret = unsafe { iter.put_current(&42, "i-am-the-new-forty-two")? }; /// assert!(ret); /// /// assert_eq!(iter.next().transpose()?, None); /// /// drop(iter); /// - /// let ret = db.get::, Str>(&wtxn, &BEI32::new(13))?; + /// let ret = db.get::(&wtxn, &13)?; /// assert_eq!(ret, None); /// - /// let ret = db.get::, Str>(&wtxn, &BEI32::new(42))?; + /// let ret = db.get::(&wtxn, &42)?; /// assert_eq!(ret, Some("i-am-the-new-forty-two")); /// /// wtxn.commit()?; @@ -781,14 +784,14 @@ impl PolyDatabase { /// let db = env.create_poly_database(&mut wtxn, Some("iter-i32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; - /// - /// let mut iter = db.rev_iter::, Str>(&wtxn)?; - /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(42), "i-am-forty-two"))); - /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(27), "i-am-twenty-seven"))); - /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(13), "i-am-thirteen"))); + /// db.put::(&mut wtxn, &42, "i-am-forty-two")?; + /// db.put::(&mut wtxn, &27, "i-am-twenty-seven")?; + /// db.put::(&mut wtxn, &13, "i-am-thirteen")?; + /// + /// let mut iter = db.rev_iter::(&wtxn)?; + /// assert_eq!(iter.next().transpose()?, Some((42, "i-am-forty-two"))); + /// assert_eq!(iter.next().transpose()?, Some((27, "i-am-twenty-seven"))); + /// assert_eq!(iter.next().transpose()?, Some((13, "i-am-thirteen"))); /// assert_eq!(iter.next().transpose()?, None); /// /// drop(iter); @@ -824,28 +827,28 @@ impl PolyDatabase { /// let db = env.create_poly_database(&mut wtxn, Some("iter-i32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; + /// db.put::(&mut wtxn, &42, "i-am-forty-two")?; + /// db.put::(&mut wtxn, &27, "i-am-twenty-seven")?; + /// db.put::(&mut wtxn, &13, "i-am-thirteen")?; /// - /// let mut iter = db.rev_iter_mut::, Str>(&mut wtxn)?; - /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(42), "i-am-forty-two"))); + /// let mut iter = db.rev_iter_mut::(&mut wtxn)?; + /// assert_eq!(iter.next().transpose()?, Some((42, "i-am-forty-two"))); /// let ret = unsafe { iter.del_current()? }; /// assert!(ret); /// - /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(27), "i-am-twenty-seven"))); - /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(13), "i-am-thirteen"))); - /// let ret = unsafe { iter.put_current(&BEI32::new(13), "i-am-the-new-thirteen")? }; + /// assert_eq!(iter.next().transpose()?, Some((27, "i-am-twenty-seven"))); + /// assert_eq!(iter.next().transpose()?, Some((13, "i-am-thirteen"))); + /// let ret = unsafe { iter.put_current(&13, "i-am-the-new-thirteen")? }; /// assert!(ret); /// /// assert_eq!(iter.next().transpose()?, None); /// /// drop(iter); /// - /// let ret = db.get::, Str>(&wtxn, &BEI32::new(42))?; + /// let ret = db.get::(&wtxn, &42)?; /// assert_eq!(ret, None); /// - /// let ret = db.get::, Str>(&wtxn, &BEI32::new(13))?; + /// let ret = db.get::(&wtxn, &13)?; /// assert_eq!(ret, Some("i-am-the-new-thirteen")); /// /// wtxn.commit()?; @@ -884,15 +887,15 @@ impl PolyDatabase { /// let db = env.create_poly_database(&mut wtxn, Some("iter-i32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(521), "i-am-five-hundred-and-twenty-one")?; - /// - /// let range = BEI32::new(27)..=BEI32::new(42); - /// let mut iter = db.range::, Str, _>(&wtxn, &range)?; - /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(27), "i-am-twenty-seven"))); - /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(42), "i-am-forty-two"))); + /// db.put::(&mut wtxn, &42, "i-am-forty-two")?; + /// db.put::(&mut wtxn, &27, "i-am-twenty-seven")?; + /// db.put::(&mut wtxn, &13, "i-am-thirteen")?; + /// db.put::(&mut wtxn, &521, "i-am-five-hundred-and-twenty-one")?; + /// + /// let range = 27..=42; + /// let mut iter = db.range::(&wtxn, &range)?; + /// assert_eq!(iter.next().transpose()?, Some((27, "i-am-twenty-seven"))); + /// assert_eq!(iter.next().transpose()?, Some((42, "i-am-forty-two"))); /// assert_eq!(iter.next().transpose()?, None); /// /// drop(iter); @@ -962,28 +965,28 @@ impl PolyDatabase { /// let db = env.create_poly_database(&mut wtxn, Some("iter-i32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(521), "i-am-five-hundred-and-twenty-one")?; - /// - /// let range = BEI32::new(27)..=BEI32::new(42); - /// let mut range = db.range_mut::, Str, _>(&mut wtxn, &range)?; - /// assert_eq!(range.next().transpose()?, Some((BEI32::new(27), "i-am-twenty-seven"))); + /// db.put::(&mut wtxn, &42, "i-am-forty-two")?; + /// db.put::(&mut wtxn, &27, "i-am-twenty-seven")?; + /// db.put::(&mut wtxn, &13, "i-am-thirteen")?; + /// db.put::(&mut wtxn, &521, "i-am-five-hundred-and-twenty-one")?; + /// + /// let range = 27..=42; + /// let mut range = db.range_mut::(&mut wtxn, &range)?; + /// assert_eq!(range.next().transpose()?, Some((27, "i-am-twenty-seven"))); /// let ret = unsafe { range.del_current()? }; /// assert!(ret); - /// assert_eq!(range.next().transpose()?, Some((BEI32::new(42), "i-am-forty-two"))); - /// let ret = unsafe { range.put_current(&BEI32::new(42), "i-am-the-new-forty-two")? }; + /// assert_eq!(range.next().transpose()?, Some((42, "i-am-forty-two"))); + /// let ret = unsafe { range.put_current(&42, "i-am-the-new-forty-two")? }; /// assert!(ret); /// /// assert_eq!(range.next().transpose()?, None); /// drop(range); /// /// - /// let mut iter = db.iter::, Str>(&wtxn)?; - /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(13), "i-am-thirteen"))); - /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(42), "i-am-the-new-forty-two"))); - /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(521), "i-am-five-hundred-and-twenty-one"))); + /// let mut iter = db.iter::(&wtxn)?; + /// assert_eq!(iter.next().transpose()?, Some((13, "i-am-thirteen"))); + /// assert_eq!(iter.next().transpose()?, Some((42, "i-am-the-new-forty-two"))); + /// assert_eq!(iter.next().transpose()?, Some((521, "i-am-five-hundred-and-twenty-one"))); /// assert_eq!(iter.next().transpose()?, None); /// /// drop(iter); @@ -1053,15 +1056,15 @@ impl PolyDatabase { /// let db = env.create_poly_database(&mut wtxn, Some("iter-i32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(521), "i-am-five-hundred-and-twenty-one")?; - /// - /// let range = BEI32::new(27)..=BEI32::new(43); - /// let mut iter = db.rev_range::, Str, _>(&wtxn, &range)?; - /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(42), "i-am-forty-two"))); - /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(27), "i-am-twenty-seven"))); + /// db.put::(&mut wtxn, &42, "i-am-forty-two")?; + /// db.put::(&mut wtxn, &27, "i-am-twenty-seven")?; + /// db.put::(&mut wtxn, &13, "i-am-thirteen")?; + /// db.put::(&mut wtxn, &521, "i-am-five-hundred-and-twenty-one")?; + /// + /// let range = 27..=43; + /// let mut iter = db.rev_range::(&wtxn, &range)?; + /// assert_eq!(iter.next().transpose()?, Some((42, "i-am-forty-two"))); + /// assert_eq!(iter.next().transpose()?, Some((27, "i-am-twenty-seven"))); /// assert_eq!(iter.next().transpose()?, None); /// /// drop(iter); @@ -1131,28 +1134,28 @@ impl PolyDatabase { /// let db = env.create_poly_database(&mut wtxn, Some("iter-i32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(521), "i-am-five-hundred-and-twenty-one")?; - /// - /// let range = BEI32::new(27)..=BEI32::new(42); - /// let mut range = db.rev_range_mut::, Str, _>(&mut wtxn, &range)?; - /// assert_eq!(range.next().transpose()?, Some((BEI32::new(42), "i-am-forty-two"))); + /// db.put::(&mut wtxn, &42, "i-am-forty-two")?; + /// db.put::(&mut wtxn, &27, "i-am-twenty-seven")?; + /// db.put::(&mut wtxn, &13, "i-am-thirteen")?; + /// db.put::(&mut wtxn, &521, "i-am-five-hundred-and-twenty-one")?; + /// + /// let range = 27..=42; + /// let mut range = db.rev_range_mut::(&mut wtxn, &range)?; + /// assert_eq!(range.next().transpose()?, Some((42, "i-am-forty-two"))); /// let ret = unsafe { range.del_current()? }; /// assert!(ret); - /// assert_eq!(range.next().transpose()?, Some((BEI32::new(27), "i-am-twenty-seven"))); - /// let ret = unsafe { range.put_current(&BEI32::new(27), "i-am-the-new-twenty-seven")? }; + /// assert_eq!(range.next().transpose()?, Some((27, "i-am-twenty-seven"))); + /// let ret = unsafe { range.put_current(&27, "i-am-the-new-twenty-seven")? }; /// assert!(ret); /// /// assert_eq!(range.next().transpose()?, None); /// drop(range); /// /// - /// let mut iter = db.iter::, Str>(&wtxn)?; - /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(13), "i-am-thirteen"))); - /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(27), "i-am-the-new-twenty-seven"))); - /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(521), "i-am-five-hundred-and-twenty-one"))); + /// let mut iter = db.iter::(&wtxn)?; + /// assert_eq!(iter.next().transpose()?, Some((13, "i-am-thirteen"))); + /// assert_eq!(iter.next().transpose()?, Some((27, "i-am-the-new-twenty-seven"))); + /// assert_eq!(iter.next().transpose()?, Some((521, "i-am-five-hundred-and-twenty-one"))); /// assert_eq!(iter.next().transpose()?, None); /// /// drop(iter); @@ -1222,16 +1225,16 @@ impl PolyDatabase { /// let db = env.create_poly_database(&mut wtxn, Some("iter-i32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put::>(&mut wtxn, "i-am-twenty-eight", &BEI32::new(28))?; - /// db.put::>(&mut wtxn, "i-am-twenty-seven", &BEI32::new(27))?; - /// db.put::>(&mut wtxn, "i-am-twenty-nine", &BEI32::new(29))?; - /// db.put::>(&mut wtxn, "i-am-forty-one", &BEI32::new(41))?; - /// db.put::>(&mut wtxn, "i-am-forty-two", &BEI32::new(42))?; - /// - /// let mut iter = db.prefix_iter::>(&mut wtxn, "i-am-twenty")?; - /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-eight", BEI32::new(28)))); - /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-nine", BEI32::new(29)))); - /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-seven", BEI32::new(27)))); + /// db.put::(&mut wtxn, "i-am-twenty-eight", &28)?; + /// db.put::(&mut wtxn, "i-am-twenty-seven", &27)?; + /// db.put::(&mut wtxn, "i-am-twenty-nine", &29)?; + /// db.put::(&mut wtxn, "i-am-forty-one", &41)?; + /// db.put::(&mut wtxn, "i-am-forty-two", &42)?; + /// + /// let mut iter = db.prefix_iter::(&mut wtxn, "i-am-twenty")?; + /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-eight", 28))); + /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-nine", 29))); + /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-seven", 27))); /// assert_eq!(iter.next().transpose()?, None); /// /// drop(iter); @@ -1278,31 +1281,31 @@ impl PolyDatabase { /// let db = env.create_poly_database(&mut wtxn, Some("iter-i32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put::>(&mut wtxn, "i-am-twenty-eight", &BEI32::new(28))?; - /// db.put::>(&mut wtxn, "i-am-twenty-seven", &BEI32::new(27))?; - /// db.put::>(&mut wtxn, "i-am-twenty-nine", &BEI32::new(29))?; - /// db.put::>(&mut wtxn, "i-am-forty-one", &BEI32::new(41))?; - /// db.put::>(&mut wtxn, "i-am-forty-two", &BEI32::new(42))?; - /// - /// let mut iter = db.prefix_iter_mut::>(&mut wtxn, "i-am-twenty")?; - /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-eight", BEI32::new(28)))); + /// db.put::(&mut wtxn, "i-am-twenty-eight", &28)?; + /// db.put::(&mut wtxn, "i-am-twenty-seven", &27)?; + /// db.put::(&mut wtxn, "i-am-twenty-nine", &29)?; + /// db.put::(&mut wtxn, "i-am-forty-one", &41)?; + /// db.put::(&mut wtxn, "i-am-forty-two", &42)?; + /// + /// let mut iter = db.prefix_iter_mut::(&mut wtxn, "i-am-twenty")?; + /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-eight", 28))); /// let ret = unsafe { iter.del_current()? }; /// assert!(ret); /// - /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-nine", BEI32::new(29)))); - /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-seven", BEI32::new(27)))); - /// let ret = unsafe { iter.put_current("i-am-twenty-seven", &BEI32::new(27000))? }; + /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-nine", 29))); + /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-seven", 27))); + /// let ret = unsafe { iter.put_current("i-am-twenty-seven", &27000)? }; /// assert!(ret); /// /// assert_eq!(iter.next().transpose()?, None); /// /// drop(iter); /// - /// let ret = db.get::>(&wtxn, "i-am-twenty-eight")?; + /// let ret = db.get::(&wtxn, "i-am-twenty-eight")?; /// assert_eq!(ret, None); /// - /// let ret = db.get::>(&wtxn, "i-am-twenty-seven")?; - /// assert_eq!(ret, Some(BEI32::new(27000))); + /// let ret = db.get::(&wtxn, "i-am-twenty-seven")?; + /// assert_eq!(ret, Some(27000)); /// /// wtxn.commit()?; /// # Ok(()) } @@ -1347,16 +1350,16 @@ impl PolyDatabase { /// let db = env.create_poly_database(&mut wtxn, Some("iter-i32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put::>(&mut wtxn, "i-am-twenty-eight", &BEI32::new(28))?; - /// db.put::>(&mut wtxn, "i-am-twenty-seven", &BEI32::new(27))?; - /// db.put::>(&mut wtxn, "i-am-twenty-nine", &BEI32::new(29))?; - /// db.put::>(&mut wtxn, "i-am-forty-one", &BEI32::new(41))?; - /// db.put::>(&mut wtxn, "i-am-forty-two", &BEI32::new(42))?; - /// - /// let mut iter = db.rev_prefix_iter::>(&mut wtxn, "i-am-twenty")?; - /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-seven", BEI32::new(27)))); - /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-nine", BEI32::new(29)))); - /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-eight", BEI32::new(28)))); + /// db.put::(&mut wtxn, "i-am-twenty-eight", &28)?; + /// db.put::(&mut wtxn, "i-am-twenty-seven", &27)?; + /// db.put::(&mut wtxn, "i-am-twenty-nine", &29)?; + /// db.put::(&mut wtxn, "i-am-forty-one", &41)?; + /// db.put::(&mut wtxn, "i-am-forty-two", &42)?; + /// + /// let mut iter = db.rev_prefix_iter::(&mut wtxn, "i-am-twenty")?; + /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-seven", 27))); + /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-nine", 29))); + /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-eight", 28))); /// assert_eq!(iter.next().transpose()?, None); /// /// drop(iter); @@ -1403,31 +1406,31 @@ impl PolyDatabase { /// let db = env.create_poly_database(&mut wtxn, Some("iter-i32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put::>(&mut wtxn, "i-am-twenty-eight", &BEI32::new(28))?; - /// db.put::>(&mut wtxn, "i-am-twenty-seven", &BEI32::new(27))?; - /// db.put::>(&mut wtxn, "i-am-twenty-nine", &BEI32::new(29))?; - /// db.put::>(&mut wtxn, "i-am-forty-one", &BEI32::new(41))?; - /// db.put::>(&mut wtxn, "i-am-forty-two", &BEI32::new(42))?; - /// - /// let mut iter = db.rev_prefix_iter_mut::>(&mut wtxn, "i-am-twenty")?; - /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-seven", BEI32::new(27)))); + /// db.put::(&mut wtxn, "i-am-twenty-eight", &28)?; + /// db.put::(&mut wtxn, "i-am-twenty-seven", &27)?; + /// db.put::(&mut wtxn, "i-am-twenty-nine", &29)?; + /// db.put::(&mut wtxn, "i-am-forty-one", &41)?; + /// db.put::(&mut wtxn, "i-am-forty-two", &42)?; + /// + /// let mut iter = db.rev_prefix_iter_mut::(&mut wtxn, "i-am-twenty")?; + /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-seven", 27))); /// let ret = unsafe { iter.del_current()? }; /// assert!(ret); /// - /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-nine", BEI32::new(29)))); - /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-eight", BEI32::new(28)))); - /// let ret = unsafe { iter.put_current("i-am-twenty-eight", &BEI32::new(28000))? }; + /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-nine", 29))); + /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-eight", 28))); + /// let ret = unsafe { iter.put_current("i-am-twenty-eight", &28000)? }; /// assert!(ret); /// /// assert_eq!(iter.next().transpose()?, None); /// /// drop(iter); /// - /// let ret = db.get::>(&wtxn, "i-am-twenty-seven")?; + /// let ret = db.get::(&wtxn, "i-am-twenty-seven")?; /// assert_eq!(ret, None); /// - /// let ret = db.get::>(&wtxn, "i-am-twenty-eight")?; - /// assert_eq!(ret, Some(BEI32::new(28000))); + /// let ret = db.get::(&wtxn, "i-am-twenty-eight")?; + /// assert_eq!(ret, Some(28000)); /// /// wtxn.commit()?; /// # Ok(()) } @@ -1469,12 +1472,12 @@ impl PolyDatabase { /// let db = env.create_poly_database(&mut wtxn, Some("iter-i32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(521), "i-am-five-hundred-and-twenty-one")?; + /// db.put::(&mut wtxn, &42, "i-am-forty-two")?; + /// db.put::(&mut wtxn, &27, "i-am-twenty-seven")?; + /// db.put::(&mut wtxn, &13, "i-am-thirteen")?; + /// db.put::(&mut wtxn, &521, "i-am-five-hundred-and-twenty-one")?; /// - /// let ret = db.get::, Str>(&mut wtxn, &BEI32::new(27))?; + /// let ret = db.get::(&mut wtxn, &27)?; /// assert_eq!(ret, Some("i-am-twenty-seven")); /// /// wtxn.commit()?; @@ -1530,11 +1533,11 @@ impl PolyDatabase { /// /// # db.clear(&mut wtxn)?; /// let value = "I am a long long long value"; - /// db.put_reserved::, _>(&mut wtxn, &BEI32::new(42), value.len(), |reserved| { + /// db.put_reserved::(&mut wtxn, &42, value.len(), |reserved| { /// reserved.write_all(value.as_bytes()) /// })?; /// - /// let ret = db.get::, Str>(&mut wtxn, &BEI32::new(42))?; + /// let ret = db.get::(&mut wtxn, &42)?; /// assert_eq!(ret, Some(value)); /// /// wtxn.commit()?; @@ -1596,12 +1599,12 @@ impl PolyDatabase { /// let db = env.create_poly_database(&mut wtxn, Some("append-i32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(521), "i-am-five-hundred-and-twenty-one")?; + /// db.put::(&mut wtxn, &13, "i-am-thirteen")?; + /// db.put::(&mut wtxn, &27, "i-am-twenty-seven")?; + /// db.put::(&mut wtxn, &42, "i-am-forty-two")?; + /// db.put::(&mut wtxn, &521, "i-am-five-hundred-and-twenty-one")?; /// - /// let ret = db.get::, Str>(&mut wtxn, &BEI32::new(27))?; + /// let ret = db.get::(&mut wtxn, &27)?; /// assert_eq!(ret, Some("i-am-twenty-seven")); /// /// wtxn.commit()?; @@ -1657,18 +1660,18 @@ impl PolyDatabase { /// let db = env.create_poly_database(&mut wtxn, Some("iter-i32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(521), "i-am-five-hundred-and-twenty-one")?; + /// db.put::(&mut wtxn, &42, "i-am-forty-two")?; + /// db.put::(&mut wtxn, &27, "i-am-twenty-seven")?; + /// db.put::(&mut wtxn, &13, "i-am-thirteen")?; + /// db.put::(&mut wtxn, &521, "i-am-five-hundred-and-twenty-one")?; /// - /// let ret = db.delete::>(&mut wtxn, &BEI32::new(27))?; + /// let ret = db.delete::(&mut wtxn, &27)?; /// assert_eq!(ret, true); /// - /// let ret = db.get::, Str>(&mut wtxn, &BEI32::new(27))?; + /// let ret = db.get::(&mut wtxn, &27)?; /// assert_eq!(ret, None); /// - /// let ret = db.delete::>(&mut wtxn, &BEI32::new(467))?; + /// let ret = db.delete::(&mut wtxn, &467)?; /// assert_eq!(ret, false); /// /// wtxn.commit()?; @@ -1723,18 +1726,18 @@ impl PolyDatabase { /// let db = env.create_poly_database(&mut wtxn, Some("iter-i32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(521), "i-am-five-hundred-and-twenty-one")?; + /// db.put::(&mut wtxn, &42, "i-am-forty-two")?; + /// db.put::(&mut wtxn, &27, "i-am-twenty-seven")?; + /// db.put::(&mut wtxn, &13, "i-am-thirteen")?; + /// db.put::(&mut wtxn, &521, "i-am-five-hundred-and-twenty-one")?; /// - /// let range = BEI32::new(27)..=BEI32::new(42); - /// let ret = db.delete_range::, _>(&mut wtxn, &range)?; + /// let range = 27..=42; + /// let ret = db.delete_range::(&mut wtxn, &range)?; /// assert_eq!(ret, 2); /// - /// let mut iter = db.iter::, Str>(&wtxn)?; - /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(13), "i-am-thirteen"))); - /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(521), "i-am-five-hundred-and-twenty-one"))); + /// let mut iter = db.iter::(&wtxn)?; + /// assert_eq!(iter.next().transpose()?, Some((13, "i-am-thirteen"))); + /// assert_eq!(iter.next().transpose()?, Some((521, "i-am-five-hundred-and-twenty-one"))); /// assert_eq!(iter.next().transpose()?, None); /// /// drop(iter); @@ -1789,10 +1792,10 @@ impl PolyDatabase { /// let db = env.create_poly_database(&mut wtxn, Some("iter-i32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; - /// db.put::, Str>(&mut wtxn, &BEI32::new(521), "i-am-five-hundred-and-twenty-one")?; + /// db.put::(&mut wtxn, &42, "i-am-forty-two")?; + /// db.put::(&mut wtxn, &27, "i-am-twenty-seven")?; + /// db.put::(&mut wtxn, &13, "i-am-thirteen")?; + /// db.put::(&mut wtxn, &521, "i-am-five-hundred-and-twenty-one")?; /// /// db.clear(&mut wtxn)?; /// @@ -1839,11 +1842,11 @@ impl PolyDatabase { /// /// # db.clear(&mut wtxn)?; /// // We remap the types for ease of use. - /// let db = db.as_uniform::, Str>(); - /// db.put(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; - /// db.put(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; - /// db.put(&mut wtxn, &BEI32::new(521), "i-am-five-hundred-and-twenty-one")?; + /// let db = db.as_uniform::(); + /// db.put(&mut wtxn, &42, "i-am-forty-two")?; + /// db.put(&mut wtxn, &27, "i-am-twenty-seven")?; + /// db.put(&mut wtxn, &13, "i-am-thirteen")?; + /// db.put(&mut wtxn, &521, "i-am-five-hundred-and-twenty-one")?; /// /// wtxn.commit()?; /// # Ok(()) } diff --git a/heed/src/db/uniform.rs b/heed/src/db/uniform.rs index b60369b2..5382e468 100644 --- a/heed/src/db/uniform.rs +++ b/heed/src/db/uniform.rs @@ -29,23 +29,23 @@ use crate::*; /// type BEI64 = I64; /// /// let mut wtxn = env.write_txn()?; -/// let db: Database, Unit> = env.create_database(&mut wtxn, Some("big-endian-iter"))?; +/// let db: Database = env.create_database(&mut wtxn, Some("big-endian-iter"))?; /// /// # db.clear(&mut wtxn)?; -/// db.put(&mut wtxn, &BEI64::new(68), &())?; -/// db.put(&mut wtxn, &BEI64::new(35), &())?; -/// db.put(&mut wtxn, &BEI64::new(0), &())?; -/// db.put(&mut wtxn, &BEI64::new(42), &())?; +/// db.put(&mut wtxn, &68, &())?; +/// db.put(&mut wtxn, &35, &())?; +/// db.put(&mut wtxn, &0, &())?; +/// db.put(&mut wtxn, &42, &())?; /// /// // you can iterate over database entries in order /// let rets: Result<_, _> = db.iter(&wtxn)?.collect(); -/// let rets: Vec<(BEI64, _)> = rets?; +/// let rets: Vec<(i64, _)> = rets?; /// /// let expected = vec![ -/// (BEI64::new(0), ()), -/// (BEI64::new(35), ()), -/// (BEI64::new(42), ()), -/// (BEI64::new(68), ()), +/// (0, ()), +/// (35, ()), +/// (42, ()), +/// (68, ()), /// ]; /// /// assert_eq!(rets, expected); @@ -76,36 +76,36 @@ use crate::*; /// type BEI64 = I64; /// /// let mut wtxn = env.write_txn()?; -/// let db: Database, Unit> = env.create_database(&mut wtxn, Some("big-endian-iter"))?; +/// let db: Database = env.create_database(&mut wtxn, Some("big-endian-iter"))?; /// /// # db.clear(&mut wtxn)?; -/// db.put(&mut wtxn, &BEI64::new(0), &())?; -/// db.put(&mut wtxn, &BEI64::new(68), &())?; -/// db.put(&mut wtxn, &BEI64::new(35), &())?; -/// db.put(&mut wtxn, &BEI64::new(42), &())?; +/// db.put(&mut wtxn, &0, &())?; +/// db.put(&mut wtxn, &68, &())?; +/// db.put(&mut wtxn, &35, &())?; +/// db.put(&mut wtxn, &42, &())?; /// /// // you can iterate over ranges too!!! -/// let range = BEI64::new(35)..=BEI64::new(42); +/// let range = 35..=42; /// let rets: Result<_, _> = db.range(&wtxn, &range)?.collect(); -/// let rets: Vec<(BEI64, _)> = rets?; +/// let rets: Vec<(i64, _)> = rets?; /// /// let expected = vec![ -/// (BEI64::new(35), ()), -/// (BEI64::new(42), ()), +/// (35, ()), +/// (42, ()), /// ]; /// /// assert_eq!(rets, expected); /// /// // even delete a range of keys -/// let range = BEI64::new(35)..=BEI64::new(42); +/// let range = 35..=42; /// let deleted: usize = db.delete_range(&mut wtxn, &range)?; /// /// let rets: Result<_, _> = db.iter(&wtxn)?.collect(); -/// let rets: Vec<(BEI64, _)> = rets?; +/// let rets: Vec<(i64, _)> = rets?; /// /// let expected = vec![ -/// (BEI64::new(0), ()), -/// (BEI64::new(68), ()), +/// (0, ()), +/// (68, ()), /// ]; /// /// assert_eq!(deleted, 2); @@ -134,6 +134,7 @@ impl Database { /// # use heed::EnvOpenOptions; /// use heed::Database; /// use heed::types::*; + /// use heed::byteorder::BigEndian; /// /// # fn main() -> Result<(), Box> { /// # let dir = tempfile::tempdir()?; @@ -141,8 +142,10 @@ impl Database { /// # .map_size(10 * 1024 * 1024) // 10MB /// # .max_dbs(3000) /// # .open(dir.path())?; + /// type BEI32= U32; + /// /// let mut wtxn = env.write_txn()?; - /// let db: Database> = env.create_database(&mut wtxn, Some("get-i32"))?; + /// let db: Database = env.create_database(&mut wtxn, Some("get-i32"))?; /// /// # db.clear(&mut wtxn)?; /// db.put(&mut wtxn, "i-am-forty-two", &42)?; @@ -189,20 +192,20 @@ impl Database { /// type BEU32 = U32; /// /// let mut wtxn = env.write_txn()?; - /// let db = env.create_database::, Unit>(&mut wtxn, Some("get-lt-u32"))?; + /// let db = env.create_database::(&mut wtxn, Some("get-lt-u32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put(&mut wtxn, &BEU32::new(27), &())?; - /// db.put(&mut wtxn, &BEU32::new(42), &())?; - /// db.put(&mut wtxn, &BEU32::new(43), &())?; + /// db.put(&mut wtxn, &27, &())?; + /// db.put(&mut wtxn, &42, &())?; + /// db.put(&mut wtxn, &43, &())?; /// - /// let ret = db.get_lower_than(&wtxn, &BEU32::new(4404))?; - /// assert_eq!(ret, Some((BEU32::new(43), ()))); + /// let ret = db.get_lower_than(&wtxn, &4404)?; + /// assert_eq!(ret, Some((43, ()))); /// - /// let ret = db.get_lower_than(&wtxn, &BEU32::new(43))?; - /// assert_eq!(ret, Some((BEU32::new(42), ()))); + /// let ret = db.get_lower_than(&wtxn, &43)?; + /// assert_eq!(ret, Some((42, ()))); /// - /// let ret = db.get_lower_than(&wtxn, &BEU32::new(27))?; + /// let ret = db.get_lower_than(&wtxn, &27)?; /// assert_eq!(ret, None); /// /// wtxn.commit()?; @@ -244,20 +247,20 @@ impl Database { /// type BEU32 = U32; /// /// let mut wtxn = env.write_txn()?; - /// let db = env.create_database::, Unit>(&mut wtxn, Some("get-lt-u32"))?; + /// let db = env.create_database::(&mut wtxn, Some("get-lt-u32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put(&mut wtxn, &BEU32::new(27), &())?; - /// db.put(&mut wtxn, &BEU32::new(42), &())?; - /// db.put(&mut wtxn, &BEU32::new(43), &())?; + /// db.put(&mut wtxn, &27, &())?; + /// db.put(&mut wtxn, &42, &())?; + /// db.put(&mut wtxn, &43, &())?; /// - /// let ret = db.get_lower_than_or_equal_to(&wtxn, &BEU32::new(4404))?; - /// assert_eq!(ret, Some((BEU32::new(43), ()))); + /// let ret = db.get_lower_than_or_equal_to(&wtxn, &4404)?; + /// assert_eq!(ret, Some((43, ()))); /// - /// let ret = db.get_lower_than_or_equal_to(&wtxn, &BEU32::new(43))?; - /// assert_eq!(ret, Some((BEU32::new(43), ()))); + /// let ret = db.get_lower_than_or_equal_to(&wtxn, &43)?; + /// assert_eq!(ret, Some((43, ()))); /// - /// let ret = db.get_lower_than_or_equal_to(&wtxn, &BEU32::new(26))?; + /// let ret = db.get_lower_than_or_equal_to(&wtxn, &26)?; /// assert_eq!(ret, None); /// /// wtxn.commit()?; @@ -299,20 +302,20 @@ impl Database { /// type BEU32 = U32; /// /// let mut wtxn = env.write_txn()?; - /// let db = env.create_database::, Unit>(&mut wtxn, Some("get-lt-u32"))?; + /// let db = env.create_database::(&mut wtxn, Some("get-lt-u32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put(&mut wtxn, &BEU32::new(27), &())?; - /// db.put(&mut wtxn, &BEU32::new(42), &())?; - /// db.put(&mut wtxn, &BEU32::new(43), &())?; + /// db.put(&mut wtxn, &27, &())?; + /// db.put(&mut wtxn, &42, &())?; + /// db.put(&mut wtxn, &43, &())?; /// - /// let ret = db.get_greater_than(&wtxn, &BEU32::new(0))?; - /// assert_eq!(ret, Some((BEU32::new(27), ()))); + /// let ret = db.get_greater_than(&wtxn, &0)?; + /// assert_eq!(ret, Some((27, ()))); /// - /// let ret = db.get_greater_than(&wtxn, &BEU32::new(42))?; - /// assert_eq!(ret, Some((BEU32::new(43), ()))); + /// let ret = db.get_greater_than(&wtxn, &42)?; + /// assert_eq!(ret, Some((43, ()))); /// - /// let ret = db.get_greater_than(&wtxn, &BEU32::new(43))?; + /// let ret = db.get_greater_than(&wtxn, &43)?; /// assert_eq!(ret, None); /// /// wtxn.commit()?; @@ -354,20 +357,20 @@ impl Database { /// type BEU32 = U32; /// /// let mut wtxn = env.write_txn()?; - /// let db = env.create_database::, Unit>(&mut wtxn, Some("get-lt-u32"))?; + /// let db = env.create_database::(&mut wtxn, Some("get-lt-u32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put(&mut wtxn, &BEU32::new(27), &())?; - /// db.put(&mut wtxn, &BEU32::new(42), &())?; - /// db.put(&mut wtxn, &BEU32::new(43), &())?; + /// db.put(&mut wtxn, &27, &())?; + /// db.put(&mut wtxn, &42, &())?; + /// db.put(&mut wtxn, &43, &())?; /// - /// let ret = db.get_greater_than_or_equal_to(&wtxn, &BEU32::new(0))?; - /// assert_eq!(ret, Some((BEU32::new(27), ()))); + /// let ret = db.get_greater_than_or_equal_to(&wtxn, &0)?; + /// assert_eq!(ret, Some((27, ()))); /// - /// let ret = db.get_greater_than_or_equal_to(&wtxn, &BEU32::new(42))?; - /// assert_eq!(ret, Some((BEU32::new(42), ()))); + /// let ret = db.get_greater_than_or_equal_to(&wtxn, &42)?; + /// assert_eq!(ret, Some((42, ()))); /// - /// let ret = db.get_greater_than_or_equal_to(&wtxn, &BEU32::new(44))?; + /// let ret = db.get_greater_than_or_equal_to(&wtxn, &44)?; /// assert_eq!(ret, None); /// /// wtxn.commit()?; @@ -408,14 +411,14 @@ impl Database { /// type BEI32 = I32; /// /// let mut wtxn = env.write_txn()?; - /// let db: Database, Str> = env.create_database(&mut wtxn, Some("first-i32"))?; + /// let db: Database = env.create_database(&mut wtxn, Some("first-i32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; + /// db.put(&mut wtxn, &42, "i-am-forty-two")?; + /// db.put(&mut wtxn, &27, "i-am-twenty-seven")?; /// /// let ret = db.first(&wtxn)?; - /// assert_eq!(ret, Some((BEI32::new(27), "i-am-twenty-seven"))); + /// assert_eq!(ret, Some((27, "i-am-twenty-seven"))); /// /// wtxn.commit()?; /// # Ok(()) } @@ -451,14 +454,14 @@ impl Database { /// type BEI32 = I32; /// /// let mut wtxn = env.write_txn()?; - /// let db: Database, Str> = env.create_database(&mut wtxn, Some("last-i32"))?; + /// let db: Database = env.create_database(&mut wtxn, Some("last-i32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; + /// db.put(&mut wtxn, &42, "i-am-forty-two")?; + /// db.put(&mut wtxn, &27, "i-am-twenty-seven")?; /// /// let ret = db.last(&wtxn)?; - /// assert_eq!(ret, Some((BEI32::new(42), "i-am-forty-two"))); + /// assert_eq!(ret, Some((42, "i-am-forty-two"))); /// /// wtxn.commit()?; /// # Ok(()) } @@ -490,18 +493,18 @@ impl Database { /// type BEI32 = I32; /// /// let mut wtxn = env.write_txn()?; - /// let db: Database, Str> = env.create_database(&mut wtxn, Some("iter-i32"))?; + /// let db: Database = env.create_database(&mut wtxn, Some("iter-i32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; - /// db.put(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; - /// db.put(&mut wtxn, &BEI32::new(521), "i-am-five-hundred-and-twenty-one")?; + /// db.put(&mut wtxn, &42, "i-am-forty-two")?; + /// db.put(&mut wtxn, &27, "i-am-twenty-seven")?; + /// db.put(&mut wtxn, &13, "i-am-thirteen")?; + /// db.put(&mut wtxn, &521, "i-am-five-hundred-and-twenty-one")?; /// /// let ret = db.len(&wtxn)?; /// assert_eq!(ret, 4); /// - /// db.delete(&mut wtxn, &BEI32::new(27))?; + /// db.delete(&mut wtxn, &27)?; /// /// let ret = db.len(&wtxn)?; /// assert_eq!(ret, 3); @@ -532,13 +535,13 @@ impl Database { /// type BEI32 = I32; /// /// let mut wtxn = env.write_txn()?; - /// let db: Database, Str> = env.create_database(&mut wtxn, Some("iter-i32"))?; + /// let db: Database = env.create_database(&mut wtxn, Some("iter-i32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; - /// db.put(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; - /// db.put(&mut wtxn, &BEI32::new(521), "i-am-five-hundred-and-twenty-one")?; + /// db.put(&mut wtxn, &42, "i-am-forty-two")?; + /// db.put(&mut wtxn, &27, "i-am-twenty-seven")?; + /// db.put(&mut wtxn, &13, "i-am-thirteen")?; + /// db.put(&mut wtxn, &521, "i-am-five-hundred-and-twenty-one")?; /// /// let ret = db.is_empty(&wtxn)?; /// assert_eq!(ret, false); @@ -574,17 +577,17 @@ impl Database { /// type BEI32 = I32; /// /// let mut wtxn = env.write_txn()?; - /// let db: Database, Str> = env.create_database(&mut wtxn, Some("iter-i32"))?; + /// let db: Database = env.create_database(&mut wtxn, Some("iter-i32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; - /// db.put(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; + /// db.put(&mut wtxn, &42, "i-am-forty-two")?; + /// db.put(&mut wtxn, &27, "i-am-twenty-seven")?; + /// db.put(&mut wtxn, &13, "i-am-thirteen")?; /// /// let mut iter = db.iter(&wtxn)?; - /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(13), "i-am-thirteen"))); - /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(27), "i-am-twenty-seven"))); - /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(42), "i-am-forty-two"))); + /// assert_eq!(iter.next().transpose()?, Some((13, "i-am-thirteen"))); + /// assert_eq!(iter.next().transpose()?, Some((27, "i-am-twenty-seven"))); + /// assert_eq!(iter.next().transpose()?, Some((42, "i-am-forty-two"))); /// assert_eq!(iter.next().transpose()?, None); /// /// drop(iter); @@ -614,31 +617,31 @@ impl Database { /// type BEI32 = I32; /// /// let mut wtxn = env.write_txn()?; - /// let db: Database, Str> = env.create_database(&mut wtxn, Some("iter-i32"))?; + /// let db: Database = env.create_database(&mut wtxn, Some("iter-i32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; - /// db.put(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; + /// db.put(&mut wtxn, &42, "i-am-forty-two")?; + /// db.put(&mut wtxn, &27, "i-am-twenty-seven")?; + /// db.put(&mut wtxn, &13, "i-am-thirteen")?; /// /// let mut iter = db.iter_mut(&mut wtxn)?; - /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(13), "i-am-thirteen"))); + /// assert_eq!(iter.next().transpose()?, Some((13, "i-am-thirteen"))); /// let ret = unsafe { iter.del_current()? }; /// assert!(ret); /// - /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(27), "i-am-twenty-seven"))); - /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(42), "i-am-forty-two"))); - /// let ret = unsafe { iter.put_current(&BEI32::new(42), "i-am-the-new-forty-two")? }; + /// assert_eq!(iter.next().transpose()?, Some((27, "i-am-twenty-seven"))); + /// assert_eq!(iter.next().transpose()?, Some((42, "i-am-forty-two"))); + /// let ret = unsafe { iter.put_current(&42, "i-am-the-new-forty-two")? }; /// assert!(ret); /// /// assert_eq!(iter.next().transpose()?, None); /// /// drop(iter); /// - /// let ret = db.get(&wtxn, &BEI32::new(13))?; + /// let ret = db.get(&wtxn, &13)?; /// assert_eq!(ret, None); /// - /// let ret = db.get(&wtxn, &BEI32::new(42))?; + /// let ret = db.get(&wtxn, &42)?; /// assert_eq!(ret, Some("i-am-the-new-forty-two")); /// /// wtxn.commit()?; @@ -667,17 +670,17 @@ impl Database { /// type BEI32 = I32; /// /// let mut wtxn = env.write_txn()?; - /// let db: Database, Str> = env.create_database(&mut wtxn, Some("iter-i32"))?; + /// let db: Database = env.create_database(&mut wtxn, Some("iter-i32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; - /// db.put(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; + /// db.put(&mut wtxn, &42, "i-am-forty-two")?; + /// db.put(&mut wtxn, &27, "i-am-twenty-seven")?; + /// db.put(&mut wtxn, &13, "i-am-thirteen")?; /// /// let mut iter = db.rev_iter(&wtxn)?; - /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(42), "i-am-forty-two"))); - /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(27), "i-am-twenty-seven"))); - /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(13), "i-am-thirteen"))); + /// assert_eq!(iter.next().transpose()?, Some((42, "i-am-forty-two"))); + /// assert_eq!(iter.next().transpose()?, Some((27, "i-am-twenty-seven"))); + /// assert_eq!(iter.next().transpose()?, Some((13, "i-am-thirteen"))); /// assert_eq!(iter.next().transpose()?, None); /// /// drop(iter); @@ -708,31 +711,31 @@ impl Database { /// type BEI32 = I32; /// /// let mut wtxn = env.write_txn()?; - /// let db: Database, Str> = env.create_database(&mut wtxn, Some("iter-i32"))?; + /// let db: Database = env.create_database(&mut wtxn, Some("iter-i32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; - /// db.put(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; + /// db.put(&mut wtxn, &42, "i-am-forty-two")?; + /// db.put(&mut wtxn, &27, "i-am-twenty-seven")?; + /// db.put(&mut wtxn, &13, "i-am-thirteen")?; /// /// let mut iter = db.rev_iter_mut(&mut wtxn)?; - /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(42), "i-am-forty-two"))); + /// assert_eq!(iter.next().transpose()?, Some((42, "i-am-forty-two"))); /// let ret = unsafe { iter.del_current()? }; /// assert!(ret); /// - /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(27), "i-am-twenty-seven"))); - /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(13), "i-am-thirteen"))); - /// let ret = unsafe { iter.put_current(&BEI32::new(13), "i-am-the-new-thirteen")? }; + /// assert_eq!(iter.next().transpose()?, Some((27, "i-am-twenty-seven"))); + /// assert_eq!(iter.next().transpose()?, Some((13, "i-am-thirteen"))); + /// let ret = unsafe { iter.put_current(&13, "i-am-the-new-thirteen")? }; /// assert!(ret); /// /// assert_eq!(iter.next().transpose()?, None); /// /// drop(iter); /// - /// let ret = db.get(&wtxn, &BEI32::new(42))?; + /// let ret = db.get(&wtxn, &42)?; /// assert_eq!(ret, None); /// - /// let ret = db.get(&wtxn, &BEI32::new(13))?; + /// let ret = db.get(&wtxn, &13)?; /// assert_eq!(ret, Some("i-am-the-new-thirteen")); /// /// wtxn.commit()?; @@ -763,18 +766,18 @@ impl Database { /// type BEI32 = I32; /// /// let mut wtxn = env.write_txn()?; - /// let db: Database, Str> = env.create_database(&mut wtxn, Some("iter-i32"))?; + /// let db: Database = env.create_database(&mut wtxn, Some("iter-i32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; - /// db.put(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; - /// db.put(&mut wtxn, &BEI32::new(521), "i-am-five-hundred-and-twenty-one")?; + /// db.put(&mut wtxn, &42, "i-am-forty-two")?; + /// db.put(&mut wtxn, &27, "i-am-twenty-seven")?; + /// db.put(&mut wtxn, &13, "i-am-thirteen")?; + /// db.put(&mut wtxn, &521, "i-am-five-hundred-and-twenty-one")?; /// - /// let range = BEI32::new(27)..=BEI32::new(42); + /// let range = 27..=42; /// let mut iter = db.range(&wtxn, &range)?; - /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(27), "i-am-twenty-seven"))); - /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(42), "i-am-forty-two"))); + /// assert_eq!(iter.next().transpose()?, Some((27, "i-am-twenty-seven"))); + /// assert_eq!(iter.next().transpose()?, Some((42, "i-am-forty-two"))); /// assert_eq!(iter.next().transpose()?, None); /// /// drop(iter); @@ -815,21 +818,21 @@ impl Database { /// type BEI32 = I32; /// /// let mut wtxn = env.write_txn()?; - /// let db: Database, Str> = env.create_database(&mut wtxn, Some("iter-i32"))?; + /// let db: Database = env.create_database(&mut wtxn, Some("iter-i32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; - /// db.put(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; - /// db.put(&mut wtxn, &BEI32::new(521), "i-am-five-hundred-and-twenty-one")?; + /// db.put(&mut wtxn, &42, "i-am-forty-two")?; + /// db.put(&mut wtxn, &27, "i-am-twenty-seven")?; + /// db.put(&mut wtxn, &13, "i-am-thirteen")?; + /// db.put(&mut wtxn, &521, "i-am-five-hundred-and-twenty-one")?; /// - /// let range = BEI32::new(27)..=BEI32::new(42); + /// let range = 27..=42; /// let mut range = db.range_mut(&mut wtxn, &range)?; - /// assert_eq!(range.next().transpose()?, Some((BEI32::new(27), "i-am-twenty-seven"))); + /// assert_eq!(range.next().transpose()?, Some((27, "i-am-twenty-seven"))); /// let ret = unsafe { range.del_current()? }; /// assert!(ret); - /// assert_eq!(range.next().transpose()?, Some((BEI32::new(42), "i-am-forty-two"))); - /// let ret = unsafe { range.put_current(&BEI32::new(42), "i-am-the-new-forty-two")? }; + /// assert_eq!(range.next().transpose()?, Some((42, "i-am-forty-two"))); + /// let ret = unsafe { range.put_current(&42, "i-am-the-new-forty-two")? }; /// assert!(ret); /// /// assert_eq!(range.next().transpose()?, None); @@ -837,9 +840,9 @@ impl Database { /// /// /// let mut iter = db.iter(&wtxn)?; - /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(13), "i-am-thirteen"))); - /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(42), "i-am-the-new-forty-two"))); - /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(521), "i-am-five-hundred-and-twenty-one"))); + /// assert_eq!(iter.next().transpose()?, Some((13, "i-am-thirteen"))); + /// assert_eq!(iter.next().transpose()?, Some((42, "i-am-the-new-forty-two"))); + /// assert_eq!(iter.next().transpose()?, Some((521, "i-am-five-hundred-and-twenty-one"))); /// assert_eq!(iter.next().transpose()?, None); /// /// drop(iter); @@ -880,18 +883,18 @@ impl Database { /// type BEI32 = I32; /// /// let mut wtxn = env.write_txn()?; - /// let db: Database, Str> = env.create_database(&mut wtxn, Some("iter-i32"))?; + /// let db: Database = env.create_database(&mut wtxn, Some("iter-i32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; - /// db.put(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; - /// db.put(&mut wtxn, &BEI32::new(521), "i-am-five-hundred-and-twenty-one")?; + /// db.put(&mut wtxn, &42, "i-am-forty-two")?; + /// db.put(&mut wtxn, &27, "i-am-twenty-seven")?; + /// db.put(&mut wtxn, &13, "i-am-thirteen")?; + /// db.put(&mut wtxn, &521, "i-am-five-hundred-and-twenty-one")?; /// - /// let range = BEI32::new(27)..=BEI32::new(43); + /// let range = 27..=43; /// let mut iter = db.rev_range(&wtxn, &range)?; - /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(42), "i-am-forty-two"))); - /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(27), "i-am-twenty-seven"))); + /// assert_eq!(iter.next().transpose()?, Some((42, "i-am-forty-two"))); + /// assert_eq!(iter.next().transpose()?, Some((27, "i-am-twenty-seven"))); /// assert_eq!(iter.next().transpose()?, None); /// /// drop(iter); @@ -932,21 +935,21 @@ impl Database { /// type BEI32 = I32; /// /// let mut wtxn = env.write_txn()?; - /// let db: Database, Str> = env.create_database(&mut wtxn, Some("iter-i32"))?; + /// let db: Database = env.create_database(&mut wtxn, Some("iter-i32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; - /// db.put(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; - /// db.put(&mut wtxn, &BEI32::new(521), "i-am-five-hundred-and-twenty-one")?; + /// db.put(&mut wtxn, &42, "i-am-forty-two")?; + /// db.put(&mut wtxn, &27, "i-am-twenty-seven")?; + /// db.put(&mut wtxn, &13, "i-am-thirteen")?; + /// db.put(&mut wtxn, &521, "i-am-five-hundred-and-twenty-one")?; /// - /// let range = BEI32::new(27)..=BEI32::new(42); + /// let range = 27..=42; /// let mut range = db.rev_range_mut(&mut wtxn, &range)?; - /// assert_eq!(range.next().transpose()?, Some((BEI32::new(42), "i-am-forty-two"))); + /// assert_eq!(range.next().transpose()?, Some((42, "i-am-forty-two"))); /// let ret = unsafe { range.del_current()? }; /// assert!(ret); - /// assert_eq!(range.next().transpose()?, Some((BEI32::new(27), "i-am-twenty-seven"))); - /// let ret = unsafe { range.put_current(&BEI32::new(27), "i-am-the-new-twenty-seven")? }; + /// assert_eq!(range.next().transpose()?, Some((27, "i-am-twenty-seven"))); + /// let ret = unsafe { range.put_current(&27, "i-am-the-new-twenty-seven")? }; /// assert!(ret); /// /// assert_eq!(range.next().transpose()?, None); @@ -954,9 +957,9 @@ impl Database { /// /// /// let mut iter = db.iter(&wtxn)?; - /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(13), "i-am-thirteen"))); - /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(27), "i-am-the-new-twenty-seven"))); - /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(521), "i-am-five-hundred-and-twenty-one"))); + /// assert_eq!(iter.next().transpose()?, Some((13, "i-am-thirteen"))); + /// assert_eq!(iter.next().transpose()?, Some((27, "i-am-the-new-twenty-seven"))); + /// assert_eq!(iter.next().transpose()?, Some((521, "i-am-five-hundred-and-twenty-one"))); /// assert_eq!(iter.next().transpose()?, None); /// /// drop(iter); @@ -997,19 +1000,19 @@ impl Database { /// type BEI32 = I32; /// /// let mut wtxn = env.write_txn()?; - /// let db: Database> = env.create_database(&mut wtxn, Some("iter-i32"))?; + /// let db: Database = env.create_database(&mut wtxn, Some("iter-i32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put(&mut wtxn, "i-am-twenty-eight", &BEI32::new(28))?; - /// db.put(&mut wtxn, "i-am-twenty-seven", &BEI32::new(27))?; - /// db.put(&mut wtxn, "i-am-twenty-nine", &BEI32::new(29))?; - /// db.put(&mut wtxn, "i-am-forty-one", &BEI32::new(41))?; - /// db.put(&mut wtxn, "i-am-forty-two", &BEI32::new(42))?; + /// db.put(&mut wtxn, "i-am-twenty-eight", &28)?; + /// db.put(&mut wtxn, "i-am-twenty-seven", &27)?; + /// db.put(&mut wtxn, "i-am-twenty-nine", &29)?; + /// db.put(&mut wtxn, "i-am-forty-one", &41)?; + /// db.put(&mut wtxn, "i-am-forty-two", &42)?; /// /// let mut iter = db.prefix_iter(&mut wtxn, "i-am-twenty")?; - /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-eight", BEI32::new(28)))); - /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-nine", BEI32::new(29)))); - /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-seven", BEI32::new(27)))); + /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-eight", 28))); + /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-nine", 29))); + /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-seven", 27))); /// assert_eq!(iter.next().transpose()?, None); /// /// drop(iter); @@ -1049,23 +1052,23 @@ impl Database { /// type BEI32 = I32; /// /// let mut wtxn = env.write_txn()?; - /// let db: Database> = env.create_database(&mut wtxn, Some("iter-i32"))?; + /// let db: Database = env.create_database(&mut wtxn, Some("iter-i32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put(&mut wtxn, "i-am-twenty-eight", &BEI32::new(28))?; - /// db.put(&mut wtxn, "i-am-twenty-seven", &BEI32::new(27))?; - /// db.put(&mut wtxn, "i-am-twenty-nine", &BEI32::new(29))?; - /// db.put(&mut wtxn, "i-am-forty-one", &BEI32::new(41))?; - /// db.put(&mut wtxn, "i-am-forty-two", &BEI32::new(42))?; + /// db.put(&mut wtxn, "i-am-twenty-eight", &28)?; + /// db.put(&mut wtxn, "i-am-twenty-seven", &27)?; + /// db.put(&mut wtxn, "i-am-twenty-nine", &29)?; + /// db.put(&mut wtxn, "i-am-forty-one", &41)?; + /// db.put(&mut wtxn, "i-am-forty-two", &42)?; /// /// let mut iter = db.prefix_iter_mut(&mut wtxn, "i-am-twenty")?; - /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-eight", BEI32::new(28)))); + /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-eight", 28))); /// let ret = unsafe { iter.del_current()? }; /// assert!(ret); /// - /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-nine", BEI32::new(29)))); - /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-seven", BEI32::new(27)))); - /// let ret = unsafe { iter.put_current("i-am-twenty-seven", &BEI32::new(27000))? }; + /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-nine", 29))); + /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-seven", 27))); + /// let ret = unsafe { iter.put_current("i-am-twenty-seven", &27000)? }; /// assert!(ret); /// /// assert_eq!(iter.next().transpose()?, None); @@ -1076,7 +1079,7 @@ impl Database { /// assert_eq!(ret, None); /// /// let ret = db.get(&wtxn, "i-am-twenty-seven")?; - /// assert_eq!(ret, Some(BEI32::new(27000))); + /// assert_eq!(ret, Some(27000)); /// /// wtxn.commit()?; /// # Ok(()) } @@ -1114,19 +1117,19 @@ impl Database { /// type BEI32 = I32; /// /// let mut wtxn = env.write_txn()?; - /// let db: Database> = env.create_database(&mut wtxn, Some("iter-i32"))?; + /// let db: Database = env.create_database(&mut wtxn, Some("iter-i32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put(&mut wtxn, "i-am-twenty-eight", &BEI32::new(28))?; - /// db.put(&mut wtxn, "i-am-twenty-seven", &BEI32::new(27))?; - /// db.put(&mut wtxn, "i-am-twenty-nine", &BEI32::new(29))?; - /// db.put(&mut wtxn, "i-am-forty-one", &BEI32::new(41))?; - /// db.put(&mut wtxn, "i-am-forty-two", &BEI32::new(42))?; + /// db.put(&mut wtxn, "i-am-twenty-eight", &28)?; + /// db.put(&mut wtxn, "i-am-twenty-seven", &27)?; + /// db.put(&mut wtxn, "i-am-twenty-nine", &29)?; + /// db.put(&mut wtxn, "i-am-forty-one", &41)?; + /// db.put(&mut wtxn, "i-am-forty-two", &42)?; /// /// let mut iter = db.rev_prefix_iter(&mut wtxn, "i-am-twenty")?; - /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-seven", BEI32::new(27)))); - /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-nine", BEI32::new(29)))); - /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-eight", BEI32::new(28)))); + /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-seven", 27))); + /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-nine", 29))); + /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-eight", 28))); /// assert_eq!(iter.next().transpose()?, None); /// /// drop(iter); @@ -1166,23 +1169,23 @@ impl Database { /// type BEI32 = I32; /// /// let mut wtxn = env.write_txn()?; - /// let db: Database> = env.create_database(&mut wtxn, Some("iter-i32"))?; + /// let db: Database = env.create_database(&mut wtxn, Some("iter-i32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put(&mut wtxn, "i-am-twenty-eight", &BEI32::new(28))?; - /// db.put(&mut wtxn, "i-am-twenty-seven", &BEI32::new(27))?; - /// db.put(&mut wtxn, "i-am-twenty-nine", &BEI32::new(29))?; - /// db.put(&mut wtxn, "i-am-forty-one", &BEI32::new(41))?; - /// db.put(&mut wtxn, "i-am-forty-two", &BEI32::new(42))?; + /// db.put(&mut wtxn, "i-am-twenty-eight", &28)?; + /// db.put(&mut wtxn, "i-am-twenty-seven", &27)?; + /// db.put(&mut wtxn, "i-am-twenty-nine", &29)?; + /// db.put(&mut wtxn, "i-am-forty-one", &41)?; + /// db.put(&mut wtxn, "i-am-forty-two", &42)?; /// /// let mut iter = db.rev_prefix_iter_mut(&mut wtxn, "i-am-twenty")?; - /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-seven", BEI32::new(27)))); + /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-seven", 27))); /// let ret = unsafe { iter.del_current()? }; /// assert!(ret); /// - /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-nine", BEI32::new(29)))); - /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-eight", BEI32::new(28)))); - /// let ret = unsafe { iter.put_current("i-am-twenty-eight", &BEI32::new(28000))? }; + /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-nine", 29))); + /// assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-eight", 28))); + /// let ret = unsafe { iter.put_current("i-am-twenty-eight", &28000)? }; /// assert!(ret); /// /// assert_eq!(iter.next().transpose()?, None); @@ -1193,7 +1196,7 @@ impl Database { /// assert_eq!(ret, None); /// /// let ret = db.get(&wtxn, "i-am-twenty-eight")?; - /// assert_eq!(ret, Some(BEI32::new(28000))); + /// assert_eq!(ret, Some(28000)); /// /// wtxn.commit()?; /// # Ok(()) } @@ -1228,15 +1231,15 @@ impl Database { /// type BEI32 = I32; /// /// let mut wtxn = env.write_txn()?; - /// let db: Database, Str> = env.create_database(&mut wtxn, Some("iter-i32"))?; + /// let db: Database = env.create_database(&mut wtxn, Some("iter-i32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; - /// db.put(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; - /// db.put(&mut wtxn, &BEI32::new(521), "i-am-five-hundred-and-twenty-one")?; + /// db.put(&mut wtxn, &42, "i-am-forty-two")?; + /// db.put(&mut wtxn, &27, "i-am-twenty-seven")?; + /// db.put(&mut wtxn, &13, "i-am-thirteen")?; + /// db.put(&mut wtxn, &521, "i-am-five-hundred-and-twenty-one")?; /// - /// let ret = db.get(&mut wtxn, &BEI32::new(27))?; + /// let ret = db.get(&mut wtxn, &27)?; /// assert_eq!(ret, Some("i-am-twenty-seven")); /// /// wtxn.commit()?; @@ -1270,15 +1273,15 @@ impl Database { /// type BEI32 = I32; /// /// let mut wtxn = env.write_txn()?; - /// let db = env.create_database::, Str>(&mut wtxn, Some("number-string"))?; + /// let db = env.create_database::(&mut wtxn, Some("number-string"))?; /// /// # db.clear(&mut wtxn)?; /// let value = "I am a long long long value"; - /// db.put_reserved(&mut wtxn, &BEI32::new(42), value.len(), |reserved| { + /// db.put_reserved(&mut wtxn, &42, value.len(), |reserved| { /// reserved.write_all(value.as_bytes()) /// })?; /// - /// let ret = db.get(&mut wtxn, &BEI32::new(42))?; + /// let ret = db.get(&mut wtxn, &42)?; /// assert_eq!(ret, Some(value)); /// /// wtxn.commit()?; @@ -1320,15 +1323,15 @@ impl Database { /// type BEI32 = I32; /// /// let mut wtxn = env.write_txn()?; - /// let db: Database, Str> = env.create_database(&mut wtxn, Some("iter-i32"))?; + /// let db: Database = env.create_database(&mut wtxn, Some("iter-i32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; - /// db.put(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; - /// db.put(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put(&mut wtxn, &BEI32::new(521), "i-am-five-hundred-and-twenty-one")?; + /// db.put(&mut wtxn, &13, "i-am-thirteen")?; + /// db.put(&mut wtxn, &27, "i-am-twenty-seven")?; + /// db.put(&mut wtxn, &42, "i-am-forty-two")?; + /// db.put(&mut wtxn, &521, "i-am-five-hundred-and-twenty-one")?; /// - /// let ret = db.get(&mut wtxn, &BEI32::new(27))?; + /// let ret = db.get(&mut wtxn, &27)?; /// assert_eq!(ret, Some("i-am-twenty-seven")); /// /// wtxn.commit()?; @@ -1363,21 +1366,21 @@ impl Database { /// type BEI32 = I32; /// /// let mut wtxn = env.write_txn()?; - /// let db: Database, Str> = env.create_database(&mut wtxn, Some("iter-i32"))?; + /// let db: Database = env.create_database(&mut wtxn, Some("iter-i32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; - /// db.put(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; - /// db.put(&mut wtxn, &BEI32::new(521), "i-am-five-hundred-and-twenty-one")?; + /// db.put(&mut wtxn, &42, "i-am-forty-two")?; + /// db.put(&mut wtxn, &27, "i-am-twenty-seven")?; + /// db.put(&mut wtxn, &13, "i-am-thirteen")?; + /// db.put(&mut wtxn, &521, "i-am-five-hundred-and-twenty-one")?; /// - /// let ret = db.delete(&mut wtxn, &BEI32::new(27))?; + /// let ret = db.delete(&mut wtxn, &27)?; /// assert_eq!(ret, true); /// - /// let ret = db.get(&mut wtxn, &BEI32::new(27))?; + /// let ret = db.get(&mut wtxn, &27)?; /// assert_eq!(ret, None); /// - /// let ret = db.delete(&mut wtxn, &BEI32::new(467))?; + /// let ret = db.delete(&mut wtxn, &467)?; /// assert_eq!(ret, false); /// /// wtxn.commit()?; @@ -1416,22 +1419,22 @@ impl Database { /// type BEI32 = I32; /// /// let mut wtxn = env.write_txn()?; - /// let db: Database, Str> = env.create_database(&mut wtxn, Some("iter-i32"))?; + /// let db: Database = env.create_database(&mut wtxn, Some("iter-i32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; - /// db.put(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; - /// db.put(&mut wtxn, &BEI32::new(521), "i-am-five-hundred-and-twenty-one")?; + /// db.put(&mut wtxn, &42, "i-am-forty-two")?; + /// db.put(&mut wtxn, &27, "i-am-twenty-seven")?; + /// db.put(&mut wtxn, &13, "i-am-thirteen")?; + /// db.put(&mut wtxn, &521, "i-am-five-hundred-and-twenty-one")?; /// - /// let range = BEI32::new(27)..=BEI32::new(42); + /// let range = 27..=42; /// let ret = db.delete_range(&mut wtxn, &range)?; /// assert_eq!(ret, 2); /// /// /// let mut iter = db.iter(&wtxn)?; - /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(13), "i-am-thirteen"))); - /// assert_eq!(iter.next().transpose()?, Some((BEI32::new(521), "i-am-five-hundred-and-twenty-one"))); + /// assert_eq!(iter.next().transpose()?, Some((13, "i-am-thirteen"))); + /// assert_eq!(iter.next().transpose()?, Some((521, "i-am-five-hundred-and-twenty-one"))); /// assert_eq!(iter.next().transpose()?, None); /// /// drop(iter); @@ -1470,13 +1473,13 @@ impl Database { /// type BEI32 = I32; /// /// let mut wtxn = env.write_txn()?; - /// let db: Database, Str> = env.create_database(&mut wtxn, Some("iter-i32"))?; + /// let db: Database = env.create_database(&mut wtxn, Some("iter-i32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; - /// db.put(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; - /// db.put(&mut wtxn, &BEI32::new(521), "i-am-five-hundred-and-twenty-one")?; + /// db.put(&mut wtxn, &42, "i-am-forty-two")?; + /// db.put(&mut wtxn, &27, "i-am-twenty-seven")?; + /// db.put(&mut wtxn, &13, "i-am-thirteen")?; + /// db.put(&mut wtxn, &521, "i-am-five-hundred-and-twenty-one")?; /// /// db.clear(&mut wtxn)?; /// @@ -1521,11 +1524,11 @@ impl Database { /// /// # db.clear(&mut wtxn)?; /// // We remap the types for ease of use. - /// let db = db.remap_types::, Str>(); - /// db.put(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; - /// db.put(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; - /// db.put(&mut wtxn, &BEI32::new(521), "i-am-five-hundred-and-twenty-one")?; + /// let db = db.remap_types::(); + /// db.put(&mut wtxn, &42, "i-am-forty-two")?; + /// db.put(&mut wtxn, &27, "i-am-twenty-seven")?; + /// db.put(&mut wtxn, &13, "i-am-thirteen")?; + /// db.put(&mut wtxn, &521, "i-am-five-hundred-and-twenty-one")?; /// /// wtxn.commit()?; /// # Ok(()) } @@ -1581,16 +1584,16 @@ impl Database { /// type BEI32 = I32; /// /// let mut wtxn = env.write_txn()?; - /// let db: Database, Str> = env.create_database(&mut wtxn, Some("iter-i32"))?; + /// let db: Database = env.create_database(&mut wtxn, Some("iter-i32"))?; /// /// # db.clear(&mut wtxn)?; - /// db.put(&mut wtxn, &BEI32::new(42), "i-am-forty-two")?; - /// db.put(&mut wtxn, &BEI32::new(27), "i-am-twenty-seven")?; - /// db.put(&mut wtxn, &BEI32::new(13), "i-am-thirteen")?; - /// db.put(&mut wtxn, &BEI32::new(521), "i-am-five-hundred-and-twenty-one")?; + /// db.put(&mut wtxn, &42, "i-am-forty-two")?; + /// db.put(&mut wtxn, &27, "i-am-twenty-seven")?; + /// db.put(&mut wtxn, &13, "i-am-thirteen")?; + /// db.put(&mut wtxn, &521, "i-am-five-hundred-and-twenty-one")?; /// /// // Check if a key exists and skip potentially expensive deserializing - /// let ret = db.as_polymorph().get::, DecodeIgnore>(&wtxn, &BEI32::new(42))?; + /// let ret = db.as_polymorph().get::(&wtxn, &42)?; /// assert!(ret.is_some()); /// /// wtxn.commit()?; diff --git a/heed/src/iter/mod.rs b/heed/src/iter/mod.rs index ed56c979..16e01ac4 100644 --- a/heed/src/iter/mod.rs +++ b/heed/src/iter/mod.rs @@ -78,40 +78,40 @@ mod tests { .unwrap(); let mut wtxn = env.write_txn().unwrap(); - let db = env.create_database::, Unit>(&mut wtxn, None).unwrap(); + let db = env.create_database::(&mut wtxn, None).unwrap(); wtxn.commit().unwrap(); type BEI32 = I32; // Create an ordered list of keys... let mut wtxn = env.write_txn().unwrap(); - db.put(&mut wtxn, &BEI32::new(1), &()).unwrap(); - db.put(&mut wtxn, &BEI32::new(2), &()).unwrap(); - db.put(&mut wtxn, &BEI32::new(3), &()).unwrap(); - db.put(&mut wtxn, &BEI32::new(4), &()).unwrap(); + db.put(&mut wtxn, &1, &()).unwrap(); + db.put(&mut wtxn, &2, &()).unwrap(); + db.put(&mut wtxn, &3, &()).unwrap(); + db.put(&mut wtxn, &4, &()).unwrap(); // Lets check that we properly get the last entry. let iter = db.iter(&wtxn).unwrap(); - assert_eq!(iter.last().transpose().unwrap(), Some((BEI32::new(4), ()))); + assert_eq!(iter.last().transpose().unwrap(), Some((4, ()))); let mut iter = db.iter(&wtxn).unwrap(); - assert_eq!(iter.next().transpose().unwrap(), Some((BEI32::new(1), ()))); - assert_eq!(iter.next().transpose().unwrap(), Some((BEI32::new(2), ()))); - assert_eq!(iter.next().transpose().unwrap(), Some((BEI32::new(3), ()))); - assert_eq!(iter.last().transpose().unwrap(), Some((BEI32::new(4), ()))); + assert_eq!(iter.next().transpose().unwrap(), Some((1, ()))); + assert_eq!(iter.next().transpose().unwrap(), Some((2, ()))); + assert_eq!(iter.next().transpose().unwrap(), Some((3, ()))); + assert_eq!(iter.last().transpose().unwrap(), Some((4, ()))); let mut iter = db.iter(&wtxn).unwrap(); - assert_eq!(iter.next().transpose().unwrap(), Some((BEI32::new(1), ()))); - assert_eq!(iter.next().transpose().unwrap(), Some((BEI32::new(2), ()))); - assert_eq!(iter.next().transpose().unwrap(), Some((BEI32::new(3), ()))); - assert_eq!(iter.next().transpose().unwrap(), Some((BEI32::new(4), ()))); + assert_eq!(iter.next().transpose().unwrap(), Some((1, ()))); + assert_eq!(iter.next().transpose().unwrap(), Some((2, ()))); + assert_eq!(iter.next().transpose().unwrap(), Some((3, ()))); + assert_eq!(iter.next().transpose().unwrap(), Some((4, ()))); assert_eq!(iter.last().transpose().unwrap(), None); let mut iter = db.iter(&wtxn).unwrap(); - assert_eq!(iter.next().transpose().unwrap(), Some((BEI32::new(1), ()))); - assert_eq!(iter.next().transpose().unwrap(), Some((BEI32::new(2), ()))); - assert_eq!(iter.next().transpose().unwrap(), Some((BEI32::new(3), ()))); - assert_eq!(iter.next().transpose().unwrap(), Some((BEI32::new(4), ()))); + assert_eq!(iter.next().transpose().unwrap(), Some((1, ()))); + assert_eq!(iter.next().transpose().unwrap(), Some((2, ()))); + assert_eq!(iter.next().transpose().unwrap(), Some((3, ()))); + assert_eq!(iter.next().transpose().unwrap(), Some((4, ()))); assert_eq!(iter.next().transpose().unwrap(), None); assert_eq!(iter.last().transpose().unwrap(), None); @@ -119,14 +119,14 @@ mod tests { // Create an ordered list of keys... let mut wtxn = env.write_txn().unwrap(); - db.put(&mut wtxn, &BEI32::new(1), &()).unwrap(); + db.put(&mut wtxn, &1, &()).unwrap(); // Lets check that we properly get the last entry. let iter = db.iter(&wtxn).unwrap(); - assert_eq!(iter.last().transpose().unwrap(), Some((BEI32::new(1), ()))); + assert_eq!(iter.last().transpose().unwrap(), Some((1, ()))); let mut iter = db.iter(&wtxn).unwrap(); - assert_eq!(iter.next().transpose().unwrap(), Some((BEI32::new(1), ()))); + assert_eq!(iter.next().transpose().unwrap(), Some((1, ()))); assert_eq!(iter.last().transpose().unwrap(), None); wtxn.abort().unwrap(); @@ -146,64 +146,64 @@ mod tests { .unwrap(); let mut wtxn = env.write_txn().unwrap(); - let db = env.create_database::, Unit>(&mut wtxn, None).unwrap(); + let db = env.create_database::(&mut wtxn, None).unwrap(); wtxn.commit().unwrap(); type BEI32 = I32; // Create an ordered list of keys... let mut wtxn = env.write_txn().unwrap(); - db.put(&mut wtxn, &BEI32::new(1), &()).unwrap(); - db.put(&mut wtxn, &BEI32::new(2), &()).unwrap(); - db.put(&mut wtxn, &BEI32::new(3), &()).unwrap(); - db.put(&mut wtxn, &BEI32::new(4), &()).unwrap(); + db.put(&mut wtxn, &1, &()).unwrap(); + db.put(&mut wtxn, &2, &()).unwrap(); + db.put(&mut wtxn, &3, &()).unwrap(); + db.put(&mut wtxn, &4, &()).unwrap(); // Lets check that we properly get the last entry. let iter = db.range(&wtxn, &(..)).unwrap(); - assert_eq!(iter.last().transpose().unwrap(), Some((BEI32::new(4), ()))); + assert_eq!(iter.last().transpose().unwrap(), Some((4, ()))); let mut iter = db.range(&wtxn, &(..)).unwrap(); - assert_eq!(iter.next().transpose().unwrap(), Some((BEI32::new(1), ()))); - assert_eq!(iter.next().transpose().unwrap(), Some((BEI32::new(2), ()))); - assert_eq!(iter.next().transpose().unwrap(), Some((BEI32::new(3), ()))); - assert_eq!(iter.last().transpose().unwrap(), Some((BEI32::new(4), ()))); + assert_eq!(iter.next().transpose().unwrap(), Some((1, ()))); + assert_eq!(iter.next().transpose().unwrap(), Some((2, ()))); + assert_eq!(iter.next().transpose().unwrap(), Some((3, ()))); + assert_eq!(iter.last().transpose().unwrap(), Some((4, ()))); let mut iter = db.range(&wtxn, &(..)).unwrap(); - assert_eq!(iter.next().transpose().unwrap(), Some((BEI32::new(1), ()))); - assert_eq!(iter.next().transpose().unwrap(), Some((BEI32::new(2), ()))); - assert_eq!(iter.next().transpose().unwrap(), Some((BEI32::new(3), ()))); - assert_eq!(iter.next().transpose().unwrap(), Some((BEI32::new(4), ()))); + assert_eq!(iter.next().transpose().unwrap(), Some((1, ()))); + assert_eq!(iter.next().transpose().unwrap(), Some((2, ()))); + assert_eq!(iter.next().transpose().unwrap(), Some((3, ()))); + assert_eq!(iter.next().transpose().unwrap(), Some((4, ()))); assert_eq!(iter.last().transpose().unwrap(), None); let mut iter = db.range(&wtxn, &(..)).unwrap(); - assert_eq!(iter.next().transpose().unwrap(), Some((BEI32::new(1), ()))); - assert_eq!(iter.next().transpose().unwrap(), Some((BEI32::new(2), ()))); - assert_eq!(iter.next().transpose().unwrap(), Some((BEI32::new(3), ()))); - assert_eq!(iter.next().transpose().unwrap(), Some((BEI32::new(4), ()))); + assert_eq!(iter.next().transpose().unwrap(), Some((1, ()))); + assert_eq!(iter.next().transpose().unwrap(), Some((2, ()))); + assert_eq!(iter.next().transpose().unwrap(), Some((3, ()))); + assert_eq!(iter.next().transpose().unwrap(), Some((4, ()))); assert_eq!(iter.next().transpose().unwrap(), None); assert_eq!(iter.last().transpose().unwrap(), None); - let range = BEI32::new(2)..=BEI32::new(4); + let range = 2..=4; let mut iter = db.range(&wtxn, &range).unwrap(); - assert_eq!(iter.next().transpose().unwrap(), Some((BEI32::new(2), ()))); - assert_eq!(iter.last().transpose().unwrap(), Some((BEI32::new(4), ()))); + assert_eq!(iter.next().transpose().unwrap(), Some((2, ()))); + assert_eq!(iter.last().transpose().unwrap(), Some((4, ()))); - let range = BEI32::new(2)..BEI32::new(4); + let range = 2..4; let mut iter = db.range(&wtxn, &range).unwrap(); - assert_eq!(iter.next().transpose().unwrap(), Some((BEI32::new(2), ()))); - assert_eq!(iter.last().transpose().unwrap(), Some((BEI32::new(3), ()))); + assert_eq!(iter.next().transpose().unwrap(), Some((2, ()))); + assert_eq!(iter.last().transpose().unwrap(), Some((3, ()))); - let range = BEI32::new(2)..BEI32::new(4); + let range = 2..4; let mut iter = db.range(&wtxn, &range).unwrap(); - assert_eq!(iter.next().transpose().unwrap(), Some((BEI32::new(2), ()))); - assert_eq!(iter.next().transpose().unwrap(), Some((BEI32::new(3), ()))); + assert_eq!(iter.next().transpose().unwrap(), Some((2, ()))); + assert_eq!(iter.next().transpose().unwrap(), Some((3, ()))); assert_eq!(iter.last().transpose().unwrap(), None); - let range = BEI32::new(2)..BEI32::new(2); + let range = 2..2; let iter = db.range(&wtxn, &range).unwrap(); assert_eq!(iter.last().transpose().unwrap(), None); - let range = BEI32::new(2)..=BEI32::new(1); + let range = 2..=1; let iter = db.range(&wtxn, &range).unwrap(); assert_eq!(iter.last().transpose().unwrap(), None); @@ -211,14 +211,14 @@ mod tests { // Create an ordered list of keys... let mut wtxn = env.write_txn().unwrap(); - db.put(&mut wtxn, &BEI32::new(1), &()).unwrap(); + db.put(&mut wtxn, &1, &()).unwrap(); // Lets check that we properly get the last entry. let iter = db.range(&wtxn, &(..)).unwrap(); - assert_eq!(iter.last().transpose().unwrap(), Some((BEI32::new(1), ()))); + assert_eq!(iter.last().transpose().unwrap(), Some((1, ()))); let mut iter = db.range(&wtxn, &(..)).unwrap(); - assert_eq!(iter.next().transpose().unwrap(), Some((BEI32::new(1), ()))); + assert_eq!(iter.next().transpose().unwrap(), Some((1, ()))); assert_eq!(iter.last().transpose().unwrap(), None); wtxn.abort().unwrap(); @@ -388,39 +388,39 @@ mod tests { .unwrap(); let mut wtxn = env.write_txn().unwrap(); - let db = env.create_database::, Unit>(&mut wtxn, None).unwrap(); + let db = env.create_database::(&mut wtxn, None).unwrap(); wtxn.commit().unwrap(); type BEI32 = I32; // Create an ordered list of keys... let mut wtxn = env.write_txn().unwrap(); - db.put(&mut wtxn, &BEI32::new(1), &()).unwrap(); - db.put(&mut wtxn, &BEI32::new(2), &()).unwrap(); - db.put(&mut wtxn, &BEI32::new(3), &()).unwrap(); - db.put(&mut wtxn, &BEI32::new(4), &()).unwrap(); + db.put(&mut wtxn, &1, &()).unwrap(); + db.put(&mut wtxn, &2, &()).unwrap(); + db.put(&mut wtxn, &3, &()).unwrap(); + db.put(&mut wtxn, &4, &()).unwrap(); // Lets check that we properly get the last entry. - let iter = db.rev_range(&wtxn, &(BEI32::new(1)..=BEI32::new(3))).unwrap(); - assert_eq!(iter.last().transpose().unwrap(), Some((BEI32::new(1), ()))); - - let mut iter = db.rev_range(&wtxn, &(BEI32::new(0)..BEI32::new(4))).unwrap(); - assert_eq!(iter.next().transpose().unwrap(), Some((BEI32::new(3), ()))); - assert_eq!(iter.next().transpose().unwrap(), Some((BEI32::new(2), ()))); - assert_eq!(iter.last().transpose().unwrap(), Some((BEI32::new(1), ()))); - - let mut iter = db.rev_range(&wtxn, &(BEI32::new(0)..=BEI32::new(5))).unwrap(); - assert_eq!(iter.next().transpose().unwrap(), Some((BEI32::new(4), ()))); - assert_eq!(iter.next().transpose().unwrap(), Some((BEI32::new(3), ()))); - assert_eq!(iter.next().transpose().unwrap(), Some((BEI32::new(2), ()))); - assert_eq!(iter.next().transpose().unwrap(), Some((BEI32::new(1), ()))); + let iter = db.rev_range(&wtxn, &(1..=3)).unwrap(); + assert_eq!(iter.last().transpose().unwrap(), Some((1, ()))); + + let mut iter = db.rev_range(&wtxn, &(0..4)).unwrap(); + assert_eq!(iter.next().transpose().unwrap(), Some((3, ()))); + assert_eq!(iter.next().transpose().unwrap(), Some((2, ()))); + assert_eq!(iter.last().transpose().unwrap(), Some((1, ()))); + + let mut iter = db.rev_range(&wtxn, &(0..=5)).unwrap(); + assert_eq!(iter.next().transpose().unwrap(), Some((4, ()))); + assert_eq!(iter.next().transpose().unwrap(), Some((3, ()))); + assert_eq!(iter.next().transpose().unwrap(), Some((2, ()))); + assert_eq!(iter.next().transpose().unwrap(), Some((1, ()))); assert_eq!(iter.last().transpose().unwrap(), None); - let iter = db.rev_range(&wtxn, &(BEI32::new(0)..=BEI32::new(5))).unwrap(); - assert_eq!(iter.last().transpose().unwrap(), Some((BEI32::new(1), ()))); + let iter = db.rev_range(&wtxn, &(0..=5)).unwrap(); + assert_eq!(iter.last().transpose().unwrap(), Some((1, ()))); - let mut iter = db.rev_range(&wtxn, &(BEI32::new(4)..=BEI32::new(4))).unwrap(); - assert_eq!(iter.next().transpose().unwrap(), Some((BEI32::new(4), ()))); + let mut iter = db.rev_range(&wtxn, &(4..=4)).unwrap(); + assert_eq!(iter.next().transpose().unwrap(), Some((4, ()))); assert_eq!(iter.last().transpose().unwrap(), None); wtxn.abort().unwrap(); From e663efdfe2b3363a2fd1da2871c0a7f72c05f766 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Sun, 30 Oct 2022 12:17:33 +0100 Subject: [PATCH 34/57] Implement Debug for more structs --- heed/src/db/polymorph.rs | 8 +++++++- heed/src/db/uniform.rs | 11 ++++++++++- heed/src/env.rs | 6 ++++++ heed/src/mdb/lmdb_flags.rs | 1 + heed/src/reserved_space.rs | 8 +++++++- 5 files changed, 31 insertions(+), 3 deletions(-) diff --git a/heed/src/db/polymorph.rs b/heed/src/db/polymorph.rs index b8a032c2..5bb73c77 100644 --- a/heed/src/db/polymorph.rs +++ b/heed/src/db/polymorph.rs @@ -1,6 +1,6 @@ use std::borrow::Cow; use std::ops::{Bound, RangeBounds}; -use std::{mem, ptr}; +use std::{fmt, mem, ptr}; use crate::mdb::error::mdb_result; use crate::mdb::ffi; @@ -1855,3 +1855,9 @@ impl PolyDatabase { Database::new(self.env_ident, self.dbi) } } + +impl fmt::Debug for PolyDatabase { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("PolyDatabase").finish() + } +} diff --git a/heed/src/db/uniform.rs b/heed/src/db/uniform.rs index 5382e468..6cbd2548 100644 --- a/heed/src/db/uniform.rs +++ b/heed/src/db/uniform.rs @@ -1,5 +1,5 @@ -use std::marker; use std::ops::RangeBounds; +use std::{any, fmt, marker}; use crate::mdb::ffi; use crate::*; @@ -1611,3 +1611,12 @@ impl Clone for Database { } impl Copy for Database {} + +impl fmt::Debug for Database { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Database") + .field("key_codec", &any::type_name::()) + .field("data_codec", &any::type_name::()) + .finish() + } +} diff --git a/heed/src/env.rs b/heed/src/env.rs index 228c338e..f42065b3 100644 --- a/heed/src/env.rs +++ b/heed/src/env.rs @@ -699,6 +699,12 @@ impl EnvClosingEvent { } } +impl fmt::Debug for EnvClosingEvent { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("EnvClosingEvent").finish() + } +} + #[cfg(test)] mod tests { use std::time::Duration; diff --git a/heed/src/mdb/lmdb_flags.rs b/heed/src/mdb/lmdb_flags.rs index 7b998bfd..9f842885 100644 --- a/heed/src/mdb/lmdb_flags.rs +++ b/heed/src/mdb/lmdb_flags.rs @@ -1,6 +1,7 @@ use lmdb_master3_sys as ffi; /// LMDB flags (see for more details). +#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[repr(u32)] pub enum Flags { MdbFixedmap = ffi::MDB_FIXEDMAP, diff --git a/heed/src/reserved_space.rs b/heed/src/reserved_space.rs index 81874d8c..83ad7237 100644 --- a/heed/src/reserved_space.rs +++ b/heed/src/reserved_space.rs @@ -1,4 +1,4 @@ -use std::io; +use std::{fmt, io}; use crate::mdb::ffi; @@ -43,3 +43,9 @@ impl io::Write for ReservedSpace { Ok(()) } } + +impl fmt::Debug for ReservedSpace { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("ReservedSpace").finish() + } +} From 22caecb66bea451c4b6e2aadc2a3b0ad4439e165 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Sun, 30 Oct 2022 12:55:09 +0100 Subject: [PATCH 35/57] Rework the abort method and remove the commit and abort from the RoTxn --- heed/examples/nested.rs | 2 +- heed/src/env.rs | 2 +- heed/src/iter/mod.rs | 16 ++++++++-------- heed/src/txn.rs | 29 ++++++++++------------------- 4 files changed, 20 insertions(+), 29 deletions(-) diff --git a/heed/examples/nested.rs b/heed/examples/nested.rs index 0bbbb6a2..cb44ec51 100644 --- a/heed/examples/nested.rs +++ b/heed/examples/nested.rs @@ -33,7 +33,7 @@ fn main() -> Result<(), Box> { println!("nested(1) \"what\": {:?}", ret); println!("nested(1) abort"); - nwtxn.abort()?; + nwtxn.abort(); let ret = db.get(&wtxn, "what")?; println!("parent \"what\": {:?}", ret); diff --git a/heed/src/env.rs b/heed/src/env.rs index f42065b3..36d21659 100644 --- a/heed/src/env.rs +++ b/heed/src/env.rs @@ -812,7 +812,7 @@ mod tests { let mut wtxn = env.write_txn().unwrap(); let _db = env.create_database::(&mut wtxn, Some("my-super-db")).unwrap(); - wtxn.abort().unwrap(); + wtxn.abort(); let rtxn = env.read_txn().unwrap(); let option = env.open_database::(&rtxn, Some("my-super-db")).unwrap(); diff --git a/heed/src/iter/mod.rs b/heed/src/iter/mod.rs index 16e01ac4..4b90fff0 100644 --- a/heed/src/iter/mod.rs +++ b/heed/src/iter/mod.rs @@ -61,7 +61,7 @@ mod tests { assert_eq!(iter.next().transpose().unwrap(), None); drop(iter); - wtxn.abort().unwrap(); + wtxn.abort(); } #[test] @@ -115,7 +115,7 @@ mod tests { assert_eq!(iter.next().transpose().unwrap(), None); assert_eq!(iter.last().transpose().unwrap(), None); - wtxn.abort().unwrap(); + wtxn.abort(); // Create an ordered list of keys... let mut wtxn = env.write_txn().unwrap(); @@ -129,7 +129,7 @@ mod tests { assert_eq!(iter.next().transpose().unwrap(), Some((1, ()))); assert_eq!(iter.last().transpose().unwrap(), None); - wtxn.abort().unwrap(); + wtxn.abort(); } #[test] @@ -207,7 +207,7 @@ mod tests { let iter = db.range(&wtxn, &range).unwrap(); assert_eq!(iter.last().transpose().unwrap(), None); - wtxn.abort().unwrap(); + wtxn.abort(); // Create an ordered list of keys... let mut wtxn = env.write_txn().unwrap(); @@ -221,7 +221,7 @@ mod tests { assert_eq!(iter.next().transpose().unwrap(), Some((1, ()))); assert_eq!(iter.last().transpose().unwrap(), None); - wtxn.abort().unwrap(); + wtxn.abort(); } #[test] @@ -296,7 +296,7 @@ mod tests { ); assert_eq!(iter.last().transpose().unwrap(), None); - wtxn.abort().unwrap(); + wtxn.abort(); } #[test] @@ -371,7 +371,7 @@ mod tests { ); assert_eq!(iter.last().transpose().unwrap(), None); - wtxn.abort().unwrap(); + wtxn.abort(); } #[test] @@ -423,6 +423,6 @@ mod tests { assert_eq!(iter.next().transpose().unwrap(), Some((4, ()))); assert_eq!(iter.last().transpose().unwrap(), None); - wtxn.abort().unwrap(); + wtxn.abort(); } } diff --git a/heed/src/txn.rs b/heed/src/txn.rs index 567ec6ba..2c892c9e 100644 --- a/heed/src/txn.rs +++ b/heed/src/txn.rs @@ -30,24 +30,12 @@ impl<'e> RoTxn<'e> { pub(crate) fn env_mut_ptr(&self) -> *mut ffi::MDB_env { self.env.env_mut_ptr() } - - pub fn commit(mut self) -> Result<()> { - let result = unsafe { mdb_result(ffi::mdb_txn_commit(self.txn)) }; - self.txn = ptr::null_mut(); - result.map_err(Into::into) - } - - pub fn abort(mut self) -> Result<()> { - let result = abort_txn(self.txn); - self.txn = ptr::null_mut(); - result - } } impl Drop for RoTxn<'_> { fn drop(&mut self) { if !self.txn.is_null() { - let _ = abort_txn(self.txn); + abort_txn(self.txn); } } } @@ -55,10 +43,10 @@ impl Drop for RoTxn<'_> { #[cfg(feature = "sync-read-txn")] unsafe impl Sync for RoTxn<'_> {} -fn abort_txn(txn: *mut ffi::MDB_txn) -> Result<()> { +fn abort_txn(txn: *mut ffi::MDB_txn) { // Asserts that the transaction hasn't been already committed. assert!(!txn.is_null()); - Ok(unsafe { ffi::mdb_txn_abort(txn) }) + unsafe { ffi::mdb_txn_abort(txn) } } /// A read-write transaction. @@ -89,12 +77,15 @@ impl<'e> RwTxn<'e, 'e> { self.txn.env.env_mut_ptr() } - pub fn commit(self) -> Result<()> { - self.txn.commit() + pub fn commit(mut self) -> Result<()> { + let result = unsafe { mdb_result(ffi::mdb_txn_commit(self.txn.txn)) }; + self.txn.txn = ptr::null_mut(); + result.map_err(Into::into) } - pub fn abort(self) -> Result<()> { - self.txn.abort() + pub fn abort(mut self) { + abort_txn(self.txn.txn); + self.txn.txn = ptr::null_mut(); } } From 634862e37f44f1c02c090aaae38e3dadbed824cf Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Sun, 30 Oct 2022 13:01:58 +0100 Subject: [PATCH 36/57] Simplify the README --- README.md | 34 +--------------------------------- 1 file changed, 1 insertion(+), 33 deletions(-) diff --git a/README.md b/README.md index 529f44ef..b5d8a8bb 100644 --- a/README.md +++ b/README.md @@ -11,39 +11,7 @@ A fully typed [LMDB](https://en.wikipedia.org/wiki/Lightning_Memory-Mapped_Datab This library is able to serialize all kind of types, not just bytes slices, even _Serde_ types are supported. -## Example Usage - -```rust -fs::create_dir_all("my-env.mdb")?; -let env = EnvOpenOptions::new().max_dbs(10).open("my-env.mdb")?; - -// We open the default unamed database. -// Specifying the type of the newly created database. -// Here we specify that the key is an str and the value a simple integer. -let mut wtxn = env.write_txn()?; -let db: Database> = env.create_database(&mut wtxn, None)?; - -// We then open a write transaction and start writing into the database. -// All of those puts are type checked at compile time, -// therefore you cannot write an integer instead of a string. -db.put(&mut wtxn, "seven", &7)?; -db.put(&mut wtxn, "zero", &0)?; -db.put(&mut wtxn, "five", &5)?; -db.put(&mut wtxn, "three", &3)?; -wtxn.commit()?; - -// We open a read transaction to check if those values are available. -// When we read we also type check at compile time. -let rtxn = env.read_txn()?; - -let ret = db.get(&rtxn, "zero")?; -assert_eq!(ret, Some(0)); - -let ret = db.get(&rtxn, "five")?; -assert_eq!(ret, Some(5)); -``` - -You want to see more about all the possibilities? Go check out [the examples](heed/examples/). +Go check out [the examples](heed/examples/). ## Building from Source From 48dfae7c24c689c57a0f02e48d52fb083c8a2992 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Thu, 17 Nov 2022 14:48:42 +0100 Subject: [PATCH 37/57] Add the vendored feature Co-authored-by: Louis --- README.md | 15 +++++++++++++++ heed/Cargo.toml | 5 ++++- lmdb-master3-sys/Cargo.toml | 7 ++++--- lmdb-master3-sys/build.rs | 2 +- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b5d8a8bb..0e65a729 100644 --- a/README.md +++ b/README.md @@ -13,8 +13,15 @@ This library is able to serialize all kind of types, not just bytes slices, even Go check out [the examples](heed/examples/). +## Vendoring + +By default, if LMDB is installed on the system, this crate will attempt to make use of the system-available LMDB. +To force installation from source, build this crate with the `vendored` feature. + ## Building from Source +### Using the system LMDB if available + If you don't already have clone the repository you can use this command: ```bash @@ -28,3 +35,11 @@ However, if you already cloned it and forgot about the initialising the submodul ```bash git submodule update --init ``` + +### Always vendoring + +```bash +git clone --recursive https://github.com/meilisearch/heed.git +cd heed +cargo build --features vendored +``` diff --git a/heed/Cargo.toml b/heed/Cargo.toml index 5fa5fc32..6c9dd168 100644 --- a/heed/Cargo.toml +++ b/heed/Cargo.toml @@ -2,7 +2,7 @@ name = "heed" version = "0.12.1" authors = ["Kerollmops "] -description = "A fully typed LMDB/MDBX wrapper with minimum overhead" +description = "A fully typed LMDB wrapper with minimum overhead" license = "MIT" repository = "https://github.com/Kerollmops/heed" keywords = ["lmdb", "database", "storage", "typed"] @@ -35,6 +35,9 @@ url = "2.3.1" # like the `EnvOpenOptions` struct. default = ["serde", "serde-bincode", "serde-json"] +# Use the provided version of LMDB instead of the one that is installed on the system. +vendored = ["lmdb-master3-sys/vendored"] + # The NO_TLS flag is automatically set on Env opening and # RoTxn implements the Sync trait. This allow the user to reference # a read-only transaction from multiple threads at the same time. diff --git a/lmdb-master3-sys/Cargo.toml b/lmdb-master3-sys/Cargo.toml index a1674bce..2ec96569 100644 --- a/lmdb-master3-sys/Cargo.toml +++ b/lmdb-master3-sys/Cargo.toml @@ -32,9 +32,10 @@ bindgen = { version = "0.60.1", default-features = false, optional = true, featu [features] default = [] -with-asan = [] -with-fuzzer = [] -with-fuzzer-no-link = [] +vendored = [] +with-asan = ["vendored"] +with-fuzzer = ["vendored"] +with-fuzzer-no-link = ["vendored"] # These features configure the MDB_IDL_LOGN macro, which determines # the size of the free and dirty page lists (and thus the amount of memory diff --git a/lmdb-master3-sys/build.rs b/lmdb-master3-sys/build.rs index c6b14c25..3552d693 100644 --- a/lmdb-master3-sys/build.rs +++ b/lmdb-master3-sys/build.rs @@ -59,7 +59,7 @@ fn main() { warn!("Building with `-fsanitize=fuzzer`."); } - if !pkg_config::find_library("lmdb").is_ok() { + if cfg!(feature = "vendored") || pkg_config::find_library("lmdb").is_err() { let mut builder = cc::Build::new(); builder From 67c1d4185997307439f7ac24e2f6cf8dfcb22e43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Thu, 17 Nov 2022 14:52:28 +0100 Subject: [PATCH 38/57] Remove the Fuchsia license --- Fuchsia_LICENSE | 24 ------------------------ 1 file changed, 24 deletions(-) delete mode 100644 Fuchsia_LICENSE diff --git a/Fuchsia_LICENSE b/Fuchsia_LICENSE deleted file mode 100644 index 7ed244f4..00000000 --- a/Fuchsia_LICENSE +++ /dev/null @@ -1,24 +0,0 @@ -Copyright 2019 The Fuchsia Authors. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - * Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above -copyright notice, this list of conditions and the following disclaimer -in the documentation and/or other materials provided with the -distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. From 98680acbc0846ea76780eee221190739482f52af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Thu, 17 Nov 2022 15:32:35 +0100 Subject: [PATCH 39/57] Reduce the number of lifetimes of the RwTxn struct --- heed/src/env.rs | 4 ++-- heed/src/txn.rs | 21 ++++++++++----------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/heed/src/env.rs b/heed/src/env.rs index 36d21659..dc5c20e0 100644 --- a/heed/src/env.rs +++ b/heed/src/env.rs @@ -571,11 +571,11 @@ impl Env { /// /// A parent transaction and its cursors may not issue any other operations than _commit_ and /// _abort_ while it has active child transactions. - pub fn nested_write_txn<'e, 'p: 'e>(&'e self, parent: &'p mut RwTxn) -> Result> { + pub fn nested_write_txn<'p>(&'p self, parent: &'p mut RwTxn) -> Result> { RwTxn::nested(self, parent) } - /// Create a transaction with read only access for use with the environment. + /// Create a transaction with read-only access for use with the environment. pub fn read_txn(&self) -> Result { RoTxn::new(self) } diff --git a/heed/src/txn.rs b/heed/src/txn.rs index 2c892c9e..1c4364d2 100644 --- a/heed/src/txn.rs +++ b/heed/src/txn.rs @@ -1,5 +1,5 @@ use std::ops::Deref; -use std::{marker, ptr}; +use std::ptr; use crate::mdb::error::mdb_result; use crate::mdb::ffi; @@ -50,27 +50,26 @@ fn abort_txn(txn: *mut ffi::MDB_txn) { } /// A read-write transaction. -pub struct RwTxn<'e, 'p> { - pub(crate) txn: RoTxn<'e>, - _parent: marker::PhantomData<&'p mut ()>, +pub struct RwTxn<'p> { + pub(crate) txn: RoTxn<'p>, } -impl<'e> RwTxn<'e, 'e> { - pub(crate) fn new(env: &'e Env) -> Result> { +impl<'p> RwTxn<'p> { + pub(crate) fn new(env: &'p Env) -> Result> { let mut txn: *mut ffi::MDB_txn = ptr::null_mut(); unsafe { mdb_result(ffi::mdb_txn_begin(env.env_mut_ptr(), ptr::null_mut(), 0, &mut txn))? }; - Ok(RwTxn { txn: RoTxn { txn, env }, _parent: marker::PhantomData }) + Ok(RwTxn { txn: RoTxn { txn, env } }) } - pub(crate) fn nested<'p: 'e>(env: &'e Env, parent: &'p mut RwTxn) -> Result> { + pub(crate) fn nested(env: &'p Env, parent: &'p mut RwTxn) -> Result> { let mut txn: *mut ffi::MDB_txn = ptr::null_mut(); let parent_ptr: *mut ffi::MDB_txn = parent.txn.txn; unsafe { mdb_result(ffi::mdb_txn_begin(env.env_mut_ptr(), parent_ptr, 0, &mut txn))? }; - Ok(RwTxn { txn: RoTxn { txn, env }, _parent: marker::PhantomData }) + Ok(RwTxn { txn: RoTxn { txn, env } }) } pub(crate) fn env_mut_ptr(&self) -> *mut ffi::MDB_env { @@ -89,8 +88,8 @@ impl<'e> RwTxn<'e, 'e> { } } -impl<'e, 'p> Deref for RwTxn<'e, 'p> { - type Target = RoTxn<'e>; +impl<'p> Deref for RwTxn<'p> { + type Target = RoTxn<'p>; fn deref(&self) -> &Self::Target { &self.txn From e147bfc62d26f25ad5ced6c4b87541c4257238fc Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Tue, 20 Dec 2022 12:04:23 +0100 Subject: [PATCH 40/57] Pull the latest changes of the mdb.master3 LMDB branch --- lmdb-master3-sys/lmdb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lmdb-master3-sys/lmdb b/lmdb-master3-sys/lmdb index 0179cfab..b9db2582 160000 --- a/lmdb-master3-sys/lmdb +++ b/lmdb-master3-sys/lmdb @@ -1 +1 @@ -Subproject commit 0179cfab57d83ab1bec9e5bae4a3ac9101820e6e +Subproject commit b9db2582cb31aa0ec88371db388095cc31ceb2f4 From 5328f337f03a793d27ac14b7a87f1472a445dcd1 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Fri, 23 Dec 2022 12:05:29 +0100 Subject: [PATCH 41/57] Update the repository of the lmdb-master3-sys TOML crate --- lmdb-master3-sys/Cargo.toml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lmdb-master3-sys/Cargo.toml b/lmdb-master3-sys/Cargo.toml index 2ec96569..fd755e5d 100644 --- a/lmdb-master3-sys/Cargo.toml +++ b/lmdb-master3-sys/Cargo.toml @@ -10,8 +10,7 @@ authors = [ license = "Apache-2.0" description = "Rust bindings for liblmdb on the mdb.master3 branch." documentation = "https://docs.rs/lmdb-master3-sys" -homepage = "https://github.com/meilisearch/heed/tree/HEAD/lmdb-master3-sys" -repository = "https://github.com/meilisearch/heed.git" +repository = "https://github.com/meilisearch/heed/tree/main/lmdb-master3-sys" keywords = ["LMDB", "database", "storage-engine", "bindings", "library"] categories = ["database", "external-ffi-bindings"] edition = "2021" From 692fbf8385372045bc2e562db08d6fb5468b09ef Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Fri, 23 Dec 2022 12:07:04 +0100 Subject: [PATCH 42/57] Remove the useless lmdb-master3-sys mdb_idl_logn features --- lmdb-master3-sys/Cargo.toml | 19 ------------------- lmdb-master3-sys/build.rs | 29 ----------------------------- 2 files changed, 48 deletions(-) diff --git a/lmdb-master3-sys/Cargo.toml b/lmdb-master3-sys/Cargo.toml index fd755e5d..61ccfc5d 100644 --- a/lmdb-master3-sys/Cargo.toml +++ b/lmdb-master3-sys/Cargo.toml @@ -35,22 +35,3 @@ vendored = [] with-asan = ["vendored"] with-fuzzer = ["vendored"] with-fuzzer-no-link = ["vendored"] - -# These features configure the MDB_IDL_LOGN macro, which determines -# the size of the free and dirty page lists (and thus the amount of memory -# allocated when opening an LMDB environment in read-write mode). -# -# Each feature defines MDB_IDL_LOGN as the value in the name of the feature. -# That means these features are mutually exclusive, and you must not specify -# more than one at the same time (or the crate will fail to compile). -# -# For more information on the motivation for these features (and their effect), -# see https://github.com/mozilla/lmdb/pull/2. -mdb_idl_logn_8 = [] -mdb_idl_logn_9 = [] -mdb_idl_logn_10 = [] -mdb_idl_logn_11 = [] -mdb_idl_logn_12 = [] -mdb_idl_logn_13 = [] -mdb_idl_logn_14 = [] -mdb_idl_logn_15 = [] diff --git a/lmdb-master3-sys/build.rs b/lmdb-master3-sys/build.rs index 3552d693..bb574e3f 100644 --- a/lmdb-master3-sys/build.rs +++ b/lmdb-master3-sys/build.rs @@ -11,34 +11,6 @@ mod generate; use std::env; use std::path::PathBuf; -#[cfg(feature = "mdb_idl_logn_8")] -const MDB_IDL_LOGN: u8 = 8; -#[cfg(feature = "mdb_idl_logn_9")] -const MDB_IDL_LOGN: u8 = 9; -#[cfg(feature = "mdb_idl_logn_10")] -const MDB_IDL_LOGN: u8 = 10; -#[cfg(feature = "mdb_idl_logn_11")] -const MDB_IDL_LOGN: u8 = 11; -#[cfg(feature = "mdb_idl_logn_12")] -const MDB_IDL_LOGN: u8 = 12; -#[cfg(feature = "mdb_idl_logn_13")] -const MDB_IDL_LOGN: u8 = 13; -#[cfg(feature = "mdb_idl_logn_14")] -const MDB_IDL_LOGN: u8 = 14; -#[cfg(feature = "mdb_idl_logn_15")] -const MDB_IDL_LOGN: u8 = 15; -#[cfg(not(any( - feature = "mdb_idl_logn_8", - feature = "mdb_idl_logn_9", - feature = "mdb_idl_logn_10", - feature = "mdb_idl_logn_11", - feature = "mdb_idl_logn_12", - feature = "mdb_idl_logn_13", - feature = "mdb_idl_logn_14", - feature = "mdb_idl_logn_15", -)))] -const MDB_IDL_LOGN: u8 = 16; - macro_rules! warn { ($message:expr) => { println!("cargo:warning={}", $message); @@ -63,7 +35,6 @@ fn main() { let mut builder = cc::Build::new(); builder - .define("MDB_IDL_LOGN", Some(MDB_IDL_LOGN.to_string().as_str())) .file(lmdb.join("mdb.c")) .file(lmdb.join("midl.c")) // https://github.com/mozilla/lmdb/blob/b7df2cac50fb41e8bd16aab4cc5fd167be9e032a/libraries/liblmdb/Makefile#L23 From 68df5e7056eb04e468fe792556e240ba1d2d9d54 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Fri, 23 Dec 2022 12:26:01 +0100 Subject: [PATCH 43/57] Use the lmdb-master3-sys crate published version --- heed/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/heed/Cargo.toml b/heed/Cargo.toml index 6c9dd168..1bae0b9b 100644 --- a/heed/Cargo.toml +++ b/heed/Cargo.toml @@ -16,7 +16,7 @@ byteorder = { version = "1.4.3", default-features = false } heed-traits = { version = "0.7.0", path = "../heed-traits" } heed-types = { version = "0.7.2", path = "../heed-types" } libc = "0.2.132" -lmdb-master3-sys = { path = "../lmdb-master3-sys" } +lmdb-master3-sys = { version = "0.1.0", path = "../lmdb-master3-sys" } once_cell = "1.14.0" page_size = "0.4.2" serde = { version = "1.0.144", features = ["derive"], optional = true } From 980050700982b39d88c0f0688084b2eeffee26c9 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Fri, 23 Dec 2022 12:38:52 +0100 Subject: [PATCH 44/57] Update dependencies with compatible ones --- heed-types/Cargo.toml | 6 +++--- heed/Cargo.toml | 12 ++++++------ lmdb-master3-sys/Cargo.toml | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/heed-types/Cargo.toml b/heed-types/Cargo.toml index 61d751f7..e7acc654 100644 --- a/heed-types/Cargo.toml +++ b/heed-types/Cargo.toml @@ -10,11 +10,11 @@ edition = "2021" [dependencies] bincode = { version = "1.3.3", optional = true } -bytemuck = { version = "1.12.1", features = ["extern_crate_alloc", "extern_crate_std"] } +bytemuck = { version = "1.12.3", features = ["extern_crate_alloc", "extern_crate_std"] } byteorder = "1.4.3" heed-traits = { version = "0.7.0", path = "../heed-traits" } -serde = { version = "1.0.144", optional = true } -serde_json = { version = "1.0.85", optional = true } +serde = { version = "1.0.151", optional = true } +serde_json = { version = "1.0.91", optional = true } [dev-dependencies] rand = "0.8.5" diff --git a/heed/Cargo.toml b/heed/Cargo.toml index 1bae0b9b..38f9e34a 100644 --- a/heed/Cargo.toml +++ b/heed/Cargo.toml @@ -11,20 +11,20 @@ readme = "../README.md" edition = "2021" [dependencies] -bytemuck = "1.12.1" +bytemuck = "1.12.3" byteorder = { version = "1.4.3", default-features = false } heed-traits = { version = "0.7.0", path = "../heed-traits" } heed-types = { version = "0.7.2", path = "../heed-types" } -libc = "0.2.132" +libc = "0.2.139" lmdb-master3-sys = { version = "0.1.0", path = "../lmdb-master3-sys" } -once_cell = "1.14.0" +once_cell = "1.16.0" page_size = "0.4.2" -serde = { version = "1.0.144", features = ["derive"], optional = true } +serde = { version = "1.0.151", features = ["derive"], optional = true } synchronoise = "1.0.1" [dev-dependencies] -serde = { version = "1.0.144", features = ["derive"] } -bytemuck = { version = "1.12.1", features = ["derive"] } +serde = { version = "1.0.151", features = ["derive"] } +bytemuck = { version = "1.12.3", features = ["derive"] } tempfile = "3.3.0" [target.'cfg(windows)'.dependencies] diff --git a/lmdb-master3-sys/Cargo.toml b/lmdb-master3-sys/Cargo.toml index 61ccfc5d..53b229de 100644 --- a/lmdb-master3-sys/Cargo.toml +++ b/lmdb-master3-sys/Cargo.toml @@ -22,11 +22,11 @@ build = "build.rs" name = "lmdb_master3_sys" [dependencies] -libc = "0.2.132" +libc = "0.2.139" [build-dependencies] -pkg-config = "0.3.25" -cc = "1.0.73" +pkg-config = "0.3.26" +cc = "1.0.78" bindgen = { version = "0.60.1", default-features = false, optional = true, features = ["runtime"] } [features] From f49685ff70655dd792bad7bfd81f4c92af997cd1 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Fri, 23 Dec 2022 12:46:55 +0100 Subject: [PATCH 45/57] Update dependencies with incompatible ones --- heed/Cargo.toml | 2 +- lmdb-master3-sys/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/heed/Cargo.toml b/heed/Cargo.toml index 38f9e34a..600093b8 100644 --- a/heed/Cargo.toml +++ b/heed/Cargo.toml @@ -18,7 +18,7 @@ heed-types = { version = "0.7.2", path = "../heed-types" } libc = "0.2.139" lmdb-master3-sys = { version = "0.1.0", path = "../lmdb-master3-sys" } once_cell = "1.16.0" -page_size = "0.4.2" +page_size = "0.5.0" serde = { version = "1.0.151", features = ["derive"], optional = true } synchronoise = "1.0.1" diff --git a/lmdb-master3-sys/Cargo.toml b/lmdb-master3-sys/Cargo.toml index 53b229de..4c005fc4 100644 --- a/lmdb-master3-sys/Cargo.toml +++ b/lmdb-master3-sys/Cargo.toml @@ -27,7 +27,7 @@ libc = "0.2.139" [build-dependencies] pkg-config = "0.3.26" cc = "1.0.78" -bindgen = { version = "0.60.1", default-features = false, optional = true, features = ["runtime"] } +bindgen = { version = "0.63.0", default-features = false, optional = true, features = ["runtime"] } [features] default = [] From 1557bc9de5e406033a249e7adf4fd3733206fcd4 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Sat, 24 Dec 2022 12:22:34 +0100 Subject: [PATCH 46/57] Delete the testdb files --- .../tests/fixtures/testdb/data.mdb | Bin 180224 -> 0 bytes .../tests/fixtures/testdb/lock.mdb | Bin 8128 -> 0 bytes lmdb-master3-sys/tests/simple.rs | 5 ++++- 3 files changed, 4 insertions(+), 1 deletion(-) delete mode 100644 lmdb-master3-sys/tests/fixtures/testdb/data.mdb delete mode 100644 lmdb-master3-sys/tests/fixtures/testdb/lock.mdb diff --git a/lmdb-master3-sys/tests/fixtures/testdb/data.mdb b/lmdb-master3-sys/tests/fixtures/testdb/data.mdb deleted file mode 100644 index e762b2e8ebd5ab9632d93a9e3f84ba2d4081e1d8..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 180224 zcmeI)F;e3&7zR+qF<_{+pri2-k^lvj_b4R8&}JqKZR!-t`Vk>*~E)SI2#Frz1ds009C7 z2oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N z0t5&UAV7cs0Rn#$nA8)pa2lST7Y~a#dDJcHdu=IY_=`BBY}!0bW|MOFyPn=mZ|`R1 z<8oOp=BqFYS1*_Mui0*&aa@zu?w%|EA5k;}2oNAZfB*pk1PBlyK!5-N0t5&UAV7cs z0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5Fqfy1^zAnpGUQ_ zX+M|$Piuzx|84bAZL2T-PjGw!1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZ zfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNA}P=Rr?TYa6c>Tfq{sweSD z=iL*tkcV~kUajT-I};rO1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk z1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oU(10+agKSvU<(&x?meBp7uReXlKL z@y=;%%cjl4WHu>xzw7DE^!9F6J}#H#qJ9U!C|tc<-oIwMebSm?{(oD2R9pG~=&2z< zfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U zAV7cs0RjXF5FkK+009Dr5EwU`)Ym%uKVNmDrg|11FwFmNs<&z*|9=R4dk`Q%fB*pk z1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs z0RjXF5FkK+z)=X4%_)kI^7(CgKZJ{Tx;(b2p5_;O^|U_Kvv@y^(|Z6y$U+{r)kn3J z|Bpr*0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF z5FkK+009C72oNAZfB*pk1PBlya0r3+-2nAO5o-Vd diff --git a/lmdb-master3-sys/tests/simple.rs b/lmdb-master3-sys/tests/simple.rs index bcf4aabb..cabeb8b3 100644 --- a/lmdb-master3-sys/tests/simple.rs +++ b/lmdb-master3-sys/tests/simple.rs @@ -1,7 +1,7 @@ use lmdb_master3_sys::*; use std::ffi::c_void; -use std::fs::File; +use std::fs::{self, File}; use std::ptr; // https://github.com/victorporof/lmdb/blob/mdb.master/libraries/liblmdb/moz-test.c @@ -46,6 +46,9 @@ fn get_file_fd(file: &File) -> std::os::unix::io::RawFd { } fn test_simple(env_path: &str) { + let _ = fs::remove_dir_all(env_path); + fs::create_dir_all(env_path).unwrap(); + let mut env: *mut MDB_env = ptr::null_mut(); let mut dbi: MDB_dbi = 0; let mut key = MDB_val { From 5ff68e2f919edc0dc08b21c54368c699664396ac Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Sat, 24 Dec 2022 15:06:24 +0100 Subject: [PATCH 47/57] Use doxygen-rs to parse the Doxygen documentation --- lmdb-master3-sys/Cargo.toml | 5 +- lmdb-master3-sys/bindgen.rs | 4 + lmdb-master3-sys/src/bindings.rs | 1209 +++--------------------------- 3 files changed, 122 insertions(+), 1096 deletions(-) diff --git a/lmdb-master3-sys/Cargo.toml b/lmdb-master3-sys/Cargo.toml index 4c005fc4..6896f76d 100644 --- a/lmdb-master3-sys/Cargo.toml +++ b/lmdb-master3-sys/Cargo.toml @@ -25,9 +25,10 @@ name = "lmdb_master3_sys" libc = "0.2.139" [build-dependencies] -pkg-config = "0.3.26" -cc = "1.0.78" bindgen = { version = "0.63.0", default-features = false, optional = true, features = ["runtime"] } +cc = "1.0.78" +doxygen-rs = "0.2.2" +pkg-config = "0.3.26" [features] default = [] diff --git a/lmdb-master3-sys/bindgen.rs b/lmdb-master3-sys/bindgen.rs index 82f78a75..2f91c765 100644 --- a/lmdb-master3-sys/bindgen.rs +++ b/lmdb-master3-sys/bindgen.rs @@ -7,6 +7,10 @@ use std::path::PathBuf; struct Callbacks; impl ParseCallbacks for Callbacks { + fn process_comment(&self, comment: &str) -> Option { + Some(doxygen_rs::transform(comment)) + } + fn int_macro(&self, name: &str, _value: i64) -> Option { match name { "MDB_SUCCESS" diff --git a/lmdb-master3-sys/src/bindings.rs b/lmdb-master3-sys/src/bindings.rs index 19d0eae5..f3c10d20 100644 --- a/lmdb-master3-sys/src/bindings.rs +++ b/lmdb-master3-sys/src/bindings.rs @@ -1,4 +1,4 @@ -/* automatically generated by rust-bindgen 0.60.1 */ +/* automatically generated by rust-bindgen 0.63.0 */ pub const MDB_FMT_Z: &[u8; 2usize] = b"z\0"; pub const MDB_RPAGE_CACHE: ::libc::c_uint = 1; @@ -62,10 +62,7 @@ pub const MDB_BAD_CHECKSUM: ::libc::c_int = -30778; pub const MDB_CRYPTO_FAIL: ::libc::c_int = -30777; pub const MDB_ENV_ENCRYPTION: ::libc::c_int = -30776; pub const MDB_LAST_ERRCODE: ::libc::c_int = -30776; -#[doc = " Unsigned type used for mapsize, entry counts and page/transaction IDs."] -#[doc = ""] -#[doc = "\tIt is normally size_t, hence the name. Defining MDB_VL32 makes it"] -#[doc = "\tuint64_t, but do not try this unless you know what you are doing."] +#[doc = "Unsigned type used for mapsize, entry counts and page/transaction IDs.\nIt is normally size_t, hence the name. Defining MDB_VL32 makes it\nuint64_t, but do not try this unless you know what you are doing.\n\n"] pub type mdb_size_t = usize; #[repr(C)] #[derive(Debug, Copy, Clone)] @@ -77,47 +74,27 @@ pub struct MDB_env { pub struct MDB_txn { _unused: [u8; 0], } -#[doc = " @brief A handle for an individual database in the DB environment."] +#[doc = "A handle for an individual database in the DB environment.\n\n"] pub type MDB_dbi = ::libc::c_uint; #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct MDB_cursor { _unused: [u8; 0], } -#[doc = " @brief Generic structure used for passing keys and data in and out"] -#[doc = " of the database."] -#[doc = ""] -#[doc = " Values returned from the database are valid only until a subsequent"] -#[doc = " update operation, or the end of the transaction. Do not modify or"] -#[doc = " free them, they commonly point into the database itself."] -#[doc = ""] -#[doc = " Key sizes must be between 1 and #mdb_env_get_maxkeysize() inclusive."] -#[doc = " The same applies to data sizes in databases with the #MDB_DUPSORT flag."] -#[doc = " Other data items can in theory be from 0 to 0xffffffff bytes long."] +#[doc = "Generic structure used for passing keys and data in and out\n\nof the database.\nValues returned from the database are valid only until a subsequent\nupdate operation, or the end of the transaction. Do not modify or\nfree them, they commonly point into the database itself.\nKey sizes must be between 1 and #mdb_env_get_maxkeysize() inclusive.\nThe same applies to data sizes in databases with the #MDB_DUPSORT flag.\nOther data items can in theory be from 0 to 0xffffffff bytes long.\n\n"] #[repr(C)] +#[derive(Debug, Copy, Clone)] pub struct MDB_val { - #[doc = "< size of the data item"] + #[doc = "size of the data item\n\n"] pub mv_size: usize, - #[doc = "< address of the data item"] + #[doc = "address of the data item\n\n"] pub mv_data: *mut ::libc::c_void, } -#[doc = " @brief A callback function used to compare two keys in a database"] +#[doc = "A callback function used to compare two keys in a database\n\n"] pub type MDB_cmp_func = ::std::option::Option< unsafe extern "C" fn(a: *const MDB_val, b: *const MDB_val) -> ::libc::c_int, >; -#[doc = " @brief A callback function used to relocate a position-dependent data item"] -#[doc = " in a fixed-address database."] -#[doc = ""] -#[doc = " The \\b newptr gives the item's desired address in"] -#[doc = " the memory map, and \\b oldptr gives its previous address. The item's actual"] -#[doc = " data resides at the address in \\b item. This callback is expected to walk"] -#[doc = " through the fields of the record in \\b item and modify any"] -#[doc = " values based at the \\b oldptr address to be relative to the \\b newptr address."] -#[doc = " @param[in,out] item The item that is to be relocated."] -#[doc = " @param[in] oldptr The previous address."] -#[doc = " @param[in] newptr The new address to relocate to."] -#[doc = " @param[in] relctx An application-provided context, set by #mdb_set_relctx()."] -#[doc = " @todo This feature is currently unimplemented."] +#[doc = "A callback function used to relocate a position-dependent data item\n\nin a fixed-address database.\nThe \\b newptr gives the item's desired address in\nthe memory map, and \\b oldptr gives its previous address. The item's actual\ndata resides at the address in \\b item. This callback is expected to walk\nthrough the fields of the record in \\b item and modify any\nvalues based at the \\b oldptr address to be relative to the \\b newptr address.\n\n# Arguments\n\n* `item` - The item that is to be relocated. [Direction: Out]\n* `oldptr` - The previous address. [Direction: In]\n* `newptr` - The new address to relocate to. [Direction: In]\n* `relctx` - An application-provided context, set by #mdb_set_relctx(). [Direction: In]\n\n# To Do\n\n* This feature is currently unimplemented.\n"] pub type MDB_rel_func = ::std::option::Option< unsafe extern "C" fn( item: *mut MDB_val, @@ -126,17 +103,7 @@ pub type MDB_rel_func = ::std::option::Option< relctx: *mut ::libc::c_void, ), >; -#[doc = " @brief A callback function used to encrypt/decrypt pages in the env."] -#[doc = ""] -#[doc = " Encrypt or decrypt the data in src and store the result in dst using the"] -#[doc = " provided key. The result must be the same number of bytes as the input."] -#[doc = " @param[in] src The input data to be transformed."] -#[doc = " @param[out] dst Storage for the result."] -#[doc = " @param[in] key An array of three values: key[0] is the encryption key,"] -#[doc = " key[1] is the initialization vector, and key[2] is the authentication"] -#[doc = " data, if any."] -#[doc = " @param[in] encdec 1 to encrypt, 0 to decrypt."] -#[doc = " @return A non-zero error value on failure and 0 on success."] +#[doc = "A callback function used to encrypt/decrypt pages in the env.\n\nEncrypt or decrypt the data in src and store the result in dst using the\nprovided key. The result must be the same number of bytes as the input.\nkey[1] is the initialization vector, and key[2] is the authentication\ndata, if any.\n\nReturns:\n\n* A non-zero error value on failure and 0 on success.\n\n# Arguments\n\n* `src` - The input data to be transformed. [Direction: In]\n* `dst` - Storage for the result. [Direction: In, Out]\n* `key` - An array of three values: key[0] is the encryption key, [Direction: In]\n* `encdec` - 1 to encrypt, 0 to decrypt. [Direction: In]\n\n"] pub type MDB_enc_func = ::std::option::Option< unsafe extern "C" fn( src: *const MDB_val, @@ -145,109 +112,86 @@ pub type MDB_enc_func = ::std::option::Option< encdec: ::libc::c_int, ) -> ::libc::c_int, >; -#[doc = " @brief A callback function used to checksum pages in the env."] -#[doc = ""] -#[doc = " Compute the checksum of the data in src and store the result in dst,"] -#[doc = " An optional key may be used with keyed hash algorithms."] -#[doc = " @param[in] src The input data to be transformed."] -#[doc = " @param[out] dst Storage for the result."] -#[doc = " @param[in] key An encryption key, if encryption was configured. This"] -#[doc = " parameter will be NULL if there is no key."] +#[doc = "A callback function used to checksum pages in the env.\n\nCompute the checksum of the data in src and store the result in dst,\nAn optional key may be used with keyed hash algorithms.\nparameter will be NULL if there is no key.\n\n# Arguments\n\n* `src` - The input data to be transformed. [Direction: In]\n* `dst` - Storage for the result. [Direction: In, Out]\n* `key` - An encryption key, if encryption was configured. This [Direction: In]\n\n"] pub type MDB_sum_func = ::std::option::Option< unsafe extern "C" fn(src: *const MDB_val, dst: *mut MDB_val, key: *const MDB_val), >; -#[doc = "< Position at first key/data item"] +#[doc = "Position at first key/data item\n\n"] pub const MDB_FIRST: MDB_cursor_op = 0; -#[doc = "< Position at first data item of current key."] -#[doc = "Only for #MDB_DUPSORT"] +#[doc = "Position at first data item of current key.\nOnly for #MDB_DUPSORT\n\n"] pub const MDB_FIRST_DUP: MDB_cursor_op = 1; -#[doc = "< Position at key/data pair. Only for #MDB_DUPSORT"] +#[doc = "Position at key/data pair. Only for #MDB_DUPSORT\n\n"] pub const MDB_GET_BOTH: MDB_cursor_op = 2; -#[doc = "< position at key, nearest data. Only for #MDB_DUPSORT"] +#[doc = "position at key, nearest data. Only for #MDB_DUPSORT\n\n"] pub const MDB_GET_BOTH_RANGE: MDB_cursor_op = 3; -#[doc = "< Return key/data at current cursor position"] +#[doc = "Return key/data at current cursor position\n\n"] pub const MDB_GET_CURRENT: MDB_cursor_op = 4; -#[doc = "< Return up to a page of duplicate data items"] -#[doc = "from current cursor position. Move cursor to prepare"] -#[doc = "for #MDB_NEXT_MULTIPLE. Only for #MDB_DUPFIXED"] +#[doc = "Return up to a page of duplicate data items\nfrom current cursor position. Move cursor to prepare\nfor #MDB_NEXT_MULTIPLE. Only for #MDB_DUPFIXED\n\n"] pub const MDB_GET_MULTIPLE: MDB_cursor_op = 5; -#[doc = "< Position at last key/data item"] +#[doc = "Position at last key/data item\n\n"] pub const MDB_LAST: MDB_cursor_op = 6; -#[doc = "< Position at last data item of current key."] -#[doc = "Only for #MDB_DUPSORT"] +#[doc = "Position at last data item of current key.\nOnly for #MDB_DUPSORT\n\n"] pub const MDB_LAST_DUP: MDB_cursor_op = 7; -#[doc = "< Position at next data item"] +#[doc = "Position at next data item\n\n"] pub const MDB_NEXT: MDB_cursor_op = 8; -#[doc = "< Position at next data item of current key."] -#[doc = "Only for #MDB_DUPSORT"] +#[doc = "Position at next data item of current key.\nOnly for #MDB_DUPSORT\n\n"] pub const MDB_NEXT_DUP: MDB_cursor_op = 9; -#[doc = "< Return up to a page of duplicate data items"] -#[doc = "from next cursor position. Move cursor to prepare"] -#[doc = "for #MDB_NEXT_MULTIPLE. Only for #MDB_DUPFIXED"] +#[doc = "Return up to a page of duplicate data items\nfrom next cursor position. Move cursor to prepare\nfor #MDB_NEXT_MULTIPLE. Only for #MDB_DUPFIXED\n\n"] pub const MDB_NEXT_MULTIPLE: MDB_cursor_op = 10; -#[doc = "< Position at first data item of next key"] +#[doc = "Position at first data item of next key\n\n"] pub const MDB_NEXT_NODUP: MDB_cursor_op = 11; -#[doc = "< Position at previous data item"] +#[doc = "Position at previous data item\n\n"] pub const MDB_PREV: MDB_cursor_op = 12; -#[doc = "< Position at previous data item of current key."] -#[doc = "Only for #MDB_DUPSORT"] +#[doc = "Position at previous data item of current key.\nOnly for #MDB_DUPSORT\n\n"] pub const MDB_PREV_DUP: MDB_cursor_op = 13; -#[doc = "< Position at last data item of previous key"] +#[doc = "Position at last data item of previous key\n\n"] pub const MDB_PREV_NODUP: MDB_cursor_op = 14; -#[doc = "< Position at specified key"] +#[doc = "Position at specified key\n\n"] pub const MDB_SET: MDB_cursor_op = 15; -#[doc = "< Position at specified key, return key + data"] +#[doc = "Position at specified key, return key + data\n\n"] pub const MDB_SET_KEY: MDB_cursor_op = 16; -#[doc = "< Position at first key greater than or equal to specified key."] +#[doc = "Position at first key greater than or equal to specified key.\n\n"] pub const MDB_SET_RANGE: MDB_cursor_op = 17; -#[doc = "< Position at previous page and return up to"] -#[doc = "a page of duplicate data items. Only for #MDB_DUPFIXED"] +#[doc = "Position at previous page and return up to\na page of duplicate data items. Only for #MDB_DUPFIXED\n\n"] pub const MDB_PREV_MULTIPLE: MDB_cursor_op = 18; -#[doc = " @brief Cursor Get operations."] -#[doc = ""] -#[doc = "\tThis is the set of all operations for retrieving data"] -#[doc = "\tusing a cursor."] +#[doc = "Cursor Get operations.\n\nThis is the set of all operations for retrieving data\nusing a cursor.\n\n"] pub type MDB_cursor_op = ::libc::c_uint; -#[doc = " @brief Statistics for a database in the environment"] +#[doc = "Statistics for a database in the environment\n\n"] #[repr(C)] +#[derive(Debug, Copy, Clone)] pub struct MDB_stat { - #[doc = "< Size of a database page."] - #[doc = "This is currently the same for all databases."] + #[doc = "Size of a database page.\nThis is currently the same for all databases.\n\n"] pub ms_psize: ::libc::c_uint, - #[doc = "< Depth (height) of the B-tree"] + #[doc = "Depth (height) of the B-tree\n\n"] pub ms_depth: ::libc::c_uint, - #[doc = "< Number of internal (non-leaf) pages"] + #[doc = "Number of internal (non-leaf) pages\n\n"] pub ms_branch_pages: mdb_size_t, - #[doc = "< Number of leaf pages"] + #[doc = "Number of leaf pages\n\n"] pub ms_leaf_pages: mdb_size_t, - #[doc = "< Number of overflow pages"] + #[doc = "Number of overflow pages\n\n"] pub ms_overflow_pages: mdb_size_t, - #[doc = "< Number of data items"] + #[doc = "Number of data items\n\n"] pub ms_entries: mdb_size_t, } -#[doc = " @brief Information about the environment"] +#[doc = "Information about the environment\n\n"] #[repr(C)] +#[derive(Debug, Copy, Clone)] pub struct MDB_envinfo { - #[doc = "< Address of map, if fixed"] + #[doc = "Address of map, if fixed\n\n"] pub me_mapaddr: *mut ::libc::c_void, - #[doc = "< Size of the data memory map"] + #[doc = "Size of the data memory map\n\n"] pub me_mapsize: mdb_size_t, - #[doc = "< ID of the last used page"] + #[doc = "ID of the last used page\n\n"] pub me_last_pgno: mdb_size_t, - #[doc = "< ID of the last committed transaction"] + #[doc = "ID of the last committed transaction\n\n"] pub me_last_txnid: mdb_size_t, - #[doc = "< max reader slots in the environment"] + #[doc = "max reader slots in the environment\n\n"] pub me_maxreaders: ::libc::c_uint, - #[doc = "< max reader slots used in the environment"] + #[doc = "max reader slots used in the environment\n\n"] pub me_numreaders: ::libc::c_uint, } extern "C" { - #[doc = " @brief Return the LMDB library version information."] - #[doc = ""] - #[doc = " @param[out] major if non-NULL, the library major version number is copied here"] - #[doc = " @param[out] minor if non-NULL, the library minor version number is copied here"] - #[doc = " @param[out] patch if non-NULL, the library patch version number is copied here"] - #[doc = " @retval \"version string\" The library version as a string"] + #[doc = "Return the LMDB library version information.\n\n# Arguments\n\n* `major` - if non-NULL, the library major version number is copied here [Direction: In, Out]\n* `minor` - if non-NULL, the library minor version number is copied here [Direction: In, Out]\n* `patch` - if non-NULL, the library patch version number is copied here [Direction: In, Out]\n\n# Return values\n* \"version string\" The library version as a string\n\n"] pub fn mdb_version( major: *mut ::libc::c_int, minor: *mut ::libc::c_int, @@ -255,157 +199,15 @@ extern "C" { ) -> *mut ::libc::c_char; } extern "C" { - #[doc = " @brief Return a string describing a given error code."] - #[doc = ""] - #[doc = " This function is a superset of the ANSI C X3.159-1989 (ANSI C) strerror(3)"] - #[doc = " function. If the error code is greater than or equal to 0, then the string"] - #[doc = " returned by the system function strerror(3) is returned. If the error code"] - #[doc = " is less than 0, an error string corresponding to the LMDB library error is"] - #[doc = " returned. See @ref errors for a list of LMDB-specific error codes."] - #[doc = " @param[in] err The error code"] - #[doc = " @retval \"error message\" The description of the error"] + #[doc = "Return a string describing a given error code.\n\nThis function is a superset of the ANSI C X3.159-1989 (ANSI C) strerror(3)\nfunction. If the error code is greater than or equal to 0, then the string\nreturned by the system function strerror(3) is returned. If the error code\nis less than 0, an error string corresponding to the LMDB library error is\nreturned. See [`errors`] for a list of LMDB-specific error codes.\n\n# Arguments\n\n* `err` - The error code [Direction: In]\n\n# Return values\n* \"error message\" The description of the error\n\n"] pub fn mdb_strerror(err: ::libc::c_int) -> *mut ::libc::c_char; } extern "C" { - #[doc = " @brief Create an LMDB environment handle."] - #[doc = ""] - #[doc = " This function allocates memory for a #MDB_env structure. To release"] - #[doc = " the allocated memory and discard the handle, call #mdb_env_close()."] - #[doc = " Before the handle may be used, it must be opened using #mdb_env_open()."] - #[doc = " Various other options may also need to be set before opening the handle,"] - #[doc = " e.g. #mdb_env_set_mapsize(), #mdb_env_set_maxreaders(), #mdb_env_set_maxdbs(),"] - #[doc = " depending on usage requirements."] - #[doc = " @param[out] env The address where the new handle will be stored"] - #[doc = " @return A non-zero error value on failure and 0 on success."] + #[doc = "Create an LMDB environment handle.\n\nThis function allocates memory for a #MDB_env structure. To release\nthe allocated memory and discard the handle, call #mdb_env_close().\nBefore the handle may be used, it must be opened using #mdb_env_open().\nVarious other options may also need to be set before opening the handle,\ne.g. #mdb_env_set_mapsize(), #mdb_env_set_maxreaders(), #mdb_env_set_maxdbs(),\ndepending on usage requirements.\n\nReturns:\n\n* A non-zero error value on failure and 0 on success.\n\n# Arguments\n\n* `env` - The address where the new handle will be stored [Direction: In, Out]\n\n"] pub fn mdb_env_create(env: *mut *mut MDB_env) -> ::libc::c_int; } extern "C" { - #[doc = " @brief Open an environment handle."] - #[doc = ""] - #[doc = " If this function fails, #mdb_env_close() must be called to discard the #MDB_env handle."] - #[doc = " @param[in] env An environment handle returned by #mdb_env_create()"] - #[doc = " @param[in] path The directory in which the database files reside. This"] - #[doc = " directory must already exist and be writable."] - #[doc = " @param[in] flags Special options for this environment. This parameter"] - #[doc = " must be set to 0 or by bitwise OR'ing together one or more of the"] - #[doc = " values described here."] - #[doc = " Flags set by mdb_env_set_flags() are also used."] - #[doc = "
    "] - #[doc = "\t
  • #MDB_FIXEDMAP"] - #[doc = " use a fixed address for the mmap region. This flag must be specified"] - #[doc = " when creating the environment, and is stored persistently in the environment."] - #[doc = "\t\tIf successful, the memory map will always reside at the same virtual address"] - #[doc = "\t\tand pointers used to reference data items in the database will be constant"] - #[doc = "\t\tacross multiple invocations. This option may not always work, depending on"] - #[doc = "\t\thow the operating system has allocated memory to shared libraries and other uses."] - #[doc = "\t\tThe feature is highly experimental."] - #[doc = "\t
  • #MDB_NOSUBDIR"] - #[doc = "\t\tBy default, LMDB creates its environment in a directory whose"] - #[doc = "\t\tpathname is given in \\b path, and creates its data and lock files"] - #[doc = "\t\tunder that directory. With this option, \\b path is used as-is for"] - #[doc = "\t\tthe database main data file. The database lock file is the \\b path"] - #[doc = "\t\twith \"-lock\" appended."] - #[doc = "\t
  • #MDB_RDONLY"] - #[doc = "\t\tOpen the environment in read-only mode. No write operations will be"] - #[doc = "\t\tallowed. LMDB will still modify the lock file - except on read-only"] - #[doc = "\t\tfilesystems, where LMDB does not use locks."] - #[doc = "\t
  • #MDB_WRITEMAP"] - #[doc = "\t\tUse a writeable memory map unless MDB_RDONLY is set. This uses"] - #[doc = "\t\tfewer mallocs but loses protection from application bugs"] - #[doc = "\t\tlike wild pointer writes and other bad updates into the database."] - #[doc = "\t\tThis may be slightly faster for DBs that fit entirely in RAM, but"] - #[doc = "\t\tis slower for DBs larger than RAM."] - #[doc = "\t\tIncompatible with nested transactions."] - #[doc = "\t\tDo not mix processes with and without MDB_WRITEMAP on the same"] - #[doc = "\t\tenvironment. This can defeat durability (#mdb_env_sync etc)."] - #[doc = "\t
  • #MDB_NOMETASYNC"] - #[doc = "\t\tFlush system buffers to disk only once per transaction, omit the"] - #[doc = "\t\tmetadata flush. Defer that until the system flushes files to disk,"] - #[doc = "\t\tor next non-MDB_RDONLY commit or #mdb_env_sync(). This optimization"] - #[doc = "\t\tmaintains database integrity, but a system crash may undo the last"] - #[doc = "\t\tcommitted transaction. I.e. it preserves the ACI (atomicity,"] - #[doc = "\t\tconsistency, isolation) but not D (durability) database property."] - #[doc = "\t\tThis flag may be changed at any time using #mdb_env_set_flags()."] - #[doc = "\t
  • #MDB_NOSYNC"] - #[doc = "\t\tDon't flush system buffers to disk when committing a transaction."] - #[doc = "\t\tThis optimization means a system crash can corrupt the database or"] - #[doc = "\t\tlose the last transactions if buffers are not yet flushed to disk."] - #[doc = "\t\tThe risk is governed by how often the system flushes dirty buffers"] - #[doc = "\t\tto disk and how often #mdb_env_sync() is called. However, if the"] - #[doc = "\t\tfilesystem preserves write order and the #MDB_WRITEMAP flag is not"] - #[doc = "\t\tused, transactions exhibit ACI (atomicity, consistency, isolation)"] - #[doc = "\t\tproperties and only lose D (durability). I.e. database integrity"] - #[doc = "\t\tis maintained, but a system crash may undo the final transactions."] - #[doc = "\t\tNote that (#MDB_NOSYNC | #MDB_WRITEMAP) leaves the system with no"] - #[doc = "\t\thint for when to write transactions to disk, unless #mdb_env_sync()"] - #[doc = "\t\tis called. (#MDB_MAPASYNC | #MDB_WRITEMAP) may be preferable."] - #[doc = "\t\tThis flag may be changed at any time using #mdb_env_set_flags()."] - #[doc = "\t
  • #MDB_MAPASYNC"] - #[doc = "\t\tWhen using #MDB_WRITEMAP, use asynchronous flushes to disk."] - #[doc = "\t\tAs with #MDB_NOSYNC, a system crash can then corrupt the"] - #[doc = "\t\tdatabase or lose the last transactions. Calling #mdb_env_sync()"] - #[doc = "\t\tensures on-disk database integrity until next commit."] - #[doc = "\t\tThis flag may be changed at any time using #mdb_env_set_flags()."] - #[doc = "\t
  • #MDB_NOTLS"] - #[doc = "\t\tDon't use Thread-Local Storage. Tie reader locktable slots to"] - #[doc = "\t\t#MDB_txn objects instead of to threads. I.e. #mdb_txn_reset() keeps"] - #[doc = "\t\tthe slot reserved for the #MDB_txn object. A thread may use parallel"] - #[doc = "\t\tread-only transactions. A read-only transaction may span threads if"] - #[doc = "\t\tthe user synchronizes its use. Applications that multiplex many"] - #[doc = "\t\tuser threads over individual OS threads need this option. Such an"] - #[doc = "\t\tapplication must also serialize the write transactions in an OS"] - #[doc = "\t\tthread, since LMDB's write locking is unaware of the user threads."] - #[doc = "\t
  • #MDB_NOLOCK"] - #[doc = "\t\tDon't do any locking. If concurrent access is anticipated, the"] - #[doc = "\t\tcaller must manage all concurrency itself. For proper operation"] - #[doc = "\t\tthe caller must enforce single-writer semantics, and must ensure"] - #[doc = "\t\tthat no readers are using old transactions while a writer is"] - #[doc = "\t\tactive. The simplest approach is to use an exclusive lock so that"] - #[doc = "\t\tno readers may be active at all when a writer begins."] - #[doc = "\t
  • #MDB_NORDAHEAD"] - #[doc = "\t\tTurn off readahead. Most operating systems perform readahead on"] - #[doc = "\t\tread requests by default. This option turns it off if the OS"] - #[doc = "\t\tsupports it. Turning it off may help random read performance"] - #[doc = "\t\twhen the DB is larger than RAM and system RAM is full."] - #[doc = "\t\tThe option is not implemented on Windows."] - #[doc = "\t
  • #MDB_NOMEMINIT"] - #[doc = "\t\tDon't initialize malloc'd memory before writing to unused spaces"] - #[doc = "\t\tin the data file. By default, memory for pages written to the data"] - #[doc = "\t\tfile is obtained using malloc. While these pages may be reused in"] - #[doc = "\t\tsubsequent transactions, freshly malloc'd pages will be initialized"] - #[doc = "\t\tto zeroes before use. This avoids persisting leftover data from other"] - #[doc = "\t\tcode (that used the heap and subsequently freed the memory) into the"] - #[doc = "\t\tdata file. Note that many other system libraries may allocate"] - #[doc = "\t\tand free memory from the heap for arbitrary uses. E.g., stdio may"] - #[doc = "\t\tuse the heap for file I/O buffers. This initialization step has a"] - #[doc = "\t\tmodest performance cost so some applications may want to disable"] - #[doc = "\t\tit using this flag. This option can be a problem for applications"] - #[doc = "\t\twhich handle sensitive data like passwords, and it makes memory"] - #[doc = "\t\tcheckers like Valgrind noisy. This flag is not needed with #MDB_WRITEMAP,"] - #[doc = "\t\twhich writes directly to the mmap instead of using malloc for pages. The"] - #[doc = "\t\tinitialization is also skipped if #MDB_RESERVE is used; the"] - #[doc = "\t\tcaller is expected to overwrite all of the memory that was"] - #[doc = "\t\treserved in that case."] - #[doc = "\t\tThis flag may be changed at any time using #mdb_env_set_flags()."] - #[doc = "\t
  • #MDB_PREVSNAPSHOT"] - #[doc = "\t\tOpen the environment with the previous snapshot rather than the latest"] - #[doc = "\t\tone. This loses the latest transaction, but may help work around some"] - #[doc = "\t\ttypes of corruption. If opened with write access, this must be the"] - #[doc = "\t\tonly process using the environment. This flag is automatically reset"] - #[doc = "\t\tafter a write transaction is successfully committed."] - #[doc = "
"] - #[doc = " @param[in] mode The UNIX permissions to set on created files and semaphores."] - #[doc = " This parameter is ignored on Windows."] - #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] - #[doc = " errors are:"] - #[doc = "
    "] - #[doc = "\t
  • #MDB_VERSION_MISMATCH - the version of the LMDB library doesn't match the"] - #[doc = "\tversion that created the database environment."] - #[doc = "\t
  • #MDB_INVALID - the environment file headers are corrupted."] - #[doc = "\t
  • ENOENT - the directory specified by the path parameter doesn't exist."] - #[doc = "\t
  • EACCES - the user didn't have permission to access the environment files."] - #[doc = "\t
  • EAGAIN - the environment was locked by another process."] - #[doc = "
"] + #[doc = "Open an environment handle.\n\nIf this function fails, #mdb_env_close() must be called to discard the #MDB_env handle.\ndirectory must already exist and be writable.\nmust be set to 0 or by bitwise OR'ing together one or more of the\nvalues described here.\nFlags set by mdb_env_set_flags() are also used.\n
    \n
  • #MDB_FIXEDMAP\nuse a fixed address for the mmap region. This flag must be specified\nwhen creating the environment, and is stored persistently in the environment.\nIf successful, the memory map will always reside at the same virtual address\nand pointers used to reference data items in the database will be constant\nacross multiple invocations. This option may not always work, depending on\nhow the operating system has allocated memory to shared libraries and other uses.\nThe feature is highly experimental.\n
  • #MDB_NOSUBDIR\nBy default, LMDB creates its environment in a directory whose\npathname is given in \\b path, and creates its data and lock files\nunder that directory. With this option, \\b path is used as-is for\nthe database main data file. The database lock file is the \\b path\nwith \"-lock\" appended.\n
  • #MDB_RDONLY\nOpen the environment in read-only mode. No write operations will be\nallowed. LMDB will still modify the lock file - except on read-only\nfilesystems, where LMDB does not use locks.\n
  • #MDB_WRITEMAP\nUse a writeable memory map unless MDB_RDONLY is set. This uses\nfewer mallocs but loses protection from application bugs\nlike wild pointer writes and other bad updates into the database.\nThis may be slightly faster for DBs that fit entirely in RAM, but\nis slower for DBs larger than RAM.\nIncompatible with nested transactions.\nDo not mix processes with and without MDB_WRITEMAP on the same\nenvironment. This can defeat durability (#mdb_env_sync etc).\n
  • #MDB_NOMETASYNC\nFlush system buffers to disk only once per transaction, omit the\nmetadata flush. Defer that until the system flushes files to disk,\nor next non-MDB_RDONLY commit or #mdb_env_sync(). This optimization\nmaintains database integrity, but a system crash may undo the last\ncommitted transaction. I.e. it preserves the ACI (atomicity,\nconsistency, isolation) but not D (durability) database property.\nThis flag may be changed at any time using #mdb_env_set_flags().\n
  • #MDB_NOSYNC\nDon't flush system buffers to disk when committing a transaction.\nThis optimization means a system crash can corrupt the database or\nlose the last transactions if buffers are not yet flushed to disk.\nThe risk is governed by how often the system flushes dirty buffers\nto disk and how often #mdb_env_sync() is called. However, if the\nfilesystem preserves write order and the #MDB_WRITEMAP flag is not\nused, transactions exhibit ACI (atomicity, consistency, isolation)\nproperties and only lose D (durability). I.e. database integrity\nis maintained, but a system crash may undo the final transactions.\nNote that (#MDB_NOSYNC | #MDB_WRITEMAP) leaves the system with no\nhint for when to write transactions to disk, unless #mdb_env_sync()\nis called. (#MDB_MAPASYNC | #MDB_WRITEMAP) may be preferable.\nThis flag may be changed at any time using #mdb_env_set_flags().\n
  • #MDB_MAPASYNC\nWhen using #MDB_WRITEMAP, use asynchronous flushes to disk.\nAs with #MDB_NOSYNC, a system crash can then corrupt the\ndatabase or lose the last transactions. Calling #mdb_env_sync()\nensures on-disk database integrity until next commit.\nThis flag may be changed at any time using #mdb_env_set_flags().\n
  • #MDB_NOTLS\nDon't use Thread-Local Storage. Tie reader locktable slots to\n#MDB_txn objects instead of to threads. I.e. #mdb_txn_reset() keeps\nthe slot reserved for the #MDB_txn object. A thread may use parallel\nread-only transactions. A read-only transaction may span threads if\nthe user synchronizes its use. Applications that multiplex many\nuser threads over individual OS threads need this option. Such an\napplication must also serialize the write transactions in an OS\nthread, since LMDB's write locking is unaware of the user threads.\n
  • #MDB_NOLOCK\nDon't do any locking. If concurrent access is anticipated, the\ncaller must manage all concurrency itself. For proper operation\nthe caller must enforce single-writer semantics, and must ensure\nthat no readers are using old transactions while a writer is\nactive. The simplest approach is to use an exclusive lock so that\nno readers may be active at all when a writer begins.\n
  • #MDB_NORDAHEAD\nTurn off readahead. Most operating systems perform readahead on\nread requests by default. This option turns it off if the OS\nsupports it. Turning it off may help random read performance\nwhen the DB is larger than RAM and system RAM is full.\nThe option is not implemented on Windows.\n
  • #MDB_NOMEMINIT\nDon't initialize malloc'd memory before writing to unused spaces\nin the data file. By default, memory for pages written to the data\nfile is obtained using malloc. While these pages may be reused in\nsubsequent transactions, freshly malloc'd pages will be initialized\nto zeroes before use. This avoids persisting leftover data from other\ncode (that used the heap and subsequently freed the memory) into the\ndata file. Note that many other system libraries may allocate\nand free memory from the heap for arbitrary uses. E.g., stdio may\nuse the heap for file I/O buffers. This initialization step has a\nmodest performance cost so some applications may want to disable\nit using this flag. This option can be a problem for applications\nwhich handle sensitive data like passwords, and it makes memory\ncheckers like Valgrind noisy. This flag is not needed with #MDB_WRITEMAP,\nwhich writes directly to the mmap instead of using malloc for pages. The\ninitialization is also skipped if #MDB_RESERVE is used; the\ncaller is expected to overwrite all of the memory that was\nreserved in that case.\nThis flag may be changed at any time using #mdb_env_set_flags().\n
  • #MDB_PREVSNAPSHOT\nOpen the environment with the previous snapshot rather than the latest\none. This loses the latest transaction, but may help work around some\ntypes of corruption. If opened with write access, this must be the\nonly process using the environment. This flag is automatically reset\nafter a write transaction is successfully committed.\n
\nThis parameter is ignored on Windows.\nerrors are:\n
    \n
  • #MDB_VERSION_MISMATCH - the version of the LMDB library doesn't match the\nversion that created the database environment.\n
  • #MDB_INVALID - the environment file headers are corrupted.\n
  • ENOENT - the directory specified by the path parameter doesn't exist.\n
  • EACCES - the user didn't have permission to access the environment files.\n
  • EAGAIN - the environment was locked by another process.\n
\n\nReturns:\n\n* A non-zero error value on failure and 0 on success. Some possible\n\n# Arguments\n\n* `env` - An environment handle returned by #mdb_env_create() [Direction: In]\n* `path` - The directory in which the database files reside. This [Direction: In]\n* `flags` - Special options for this environment. This parameter [Direction: In]\n* `mode` - The UNIX permissions to set on created files and semaphores. [Direction: In]\n\n"] pub fn mdb_env_open( env: *mut MDB_env, path: *const ::libc::c_char, @@ -414,59 +216,15 @@ extern "C" { ) -> ::libc::c_int; } extern "C" { - #[doc = " @brief Copy an LMDB environment to the specified path."] - #[doc = ""] - #[doc = " This function may be used to make a backup of an existing environment."] - #[doc = " No lockfile is created, since it gets recreated at need."] - #[doc = " @note This call can trigger significant file size growth if run in"] - #[doc = " parallel with write transactions, because it employs a read-only"] - #[doc = " transaction. See long-lived transactions under @ref caveats_sec."] - #[doc = " @param[in] env An environment handle returned by #mdb_env_create(). It"] - #[doc = " must have already been opened successfully."] - #[doc = " @param[in] path The directory in which the copy will reside. This"] - #[doc = " directory must already exist and be writable but must otherwise be"] - #[doc = " empty."] - #[doc = " @return A non-zero error value on failure and 0 on success."] + #[doc = "Copy an LMDB environment to the specified path.\n\nThis function may be used to make a backup of an existing environment.\nNo lockfile is created, since it gets recreated at need.\nparallel with write transactions, because it employs a read-only\ntransaction. See long-lived transactions under [`caveats_sec`]\nmust have already been opened successfully.\ndirectory must already exist and be writable but must otherwise be\nempty.\n\nReturns:\n\n* A non-zero error value on failure and 0 on success.\n\n# Arguments\n\n* `env` - An environment handle returned by #mdb_env_create(). It [Direction: In]\n* `path` - The directory in which the copy will reside. This [Direction: In]\n\n# Notes\n\n* This call can trigger significant file size growth if run in\n\n"] pub fn mdb_env_copy(env: *mut MDB_env, path: *const ::libc::c_char) -> ::libc::c_int; } extern "C" { - #[doc = " @brief Copy an LMDB environment to the specified file descriptor."] - #[doc = ""] - #[doc = " This function may be used to make a backup of an existing environment."] - #[doc = " No lockfile is created, since it gets recreated at need."] - #[doc = " @note This call can trigger significant file size growth if run in"] - #[doc = " parallel with write transactions, because it employs a read-only"] - #[doc = " transaction. See long-lived transactions under @ref caveats_sec."] - #[doc = " @param[in] env An environment handle returned by #mdb_env_create(). It"] - #[doc = " must have already been opened successfully."] - #[doc = " @param[in] fd The filedescriptor to write the copy to. It must"] - #[doc = " have already been opened for Write access."] - #[doc = " @return A non-zero error value on failure and 0 on success."] + #[doc = "Copy an LMDB environment to the specified file descriptor.\n\nThis function may be used to make a backup of an existing environment.\nNo lockfile is created, since it gets recreated at need.\nparallel with write transactions, because it employs a read-only\ntransaction. See long-lived transactions under [`caveats_sec`]\nmust have already been opened successfully.\nhave already been opened for Write access.\n\nReturns:\n\n* A non-zero error value on failure and 0 on success.\n\n# Arguments\n\n* `env` - An environment handle returned by #mdb_env_create(). It [Direction: In]\n* `fd` - The filedescriptor to write the copy to. It must [Direction: In]\n\n# Notes\n\n* This call can trigger significant file size growth if run in\n\n"] pub fn mdb_env_copyfd(env: *mut MDB_env, fd: mdb_filehandle_t) -> ::libc::c_int; } extern "C" { - #[doc = " @brief Copy an LMDB environment to the specified path, with options."] - #[doc = ""] - #[doc = " This function may be used to make a backup of an existing environment."] - #[doc = " No lockfile is created, since it gets recreated at need."] - #[doc = " @note This call can trigger significant file size growth if run in"] - #[doc = " parallel with write transactions, because it employs a read-only"] - #[doc = " transaction. See long-lived transactions under @ref caveats_sec."] - #[doc = " @param[in] env An environment handle returned by #mdb_env_create(). It"] - #[doc = " must have already been opened successfully."] - #[doc = " @param[in] path The directory in which the copy will reside. This"] - #[doc = " directory must already exist and be writable but must otherwise be"] - #[doc = " empty."] - #[doc = " @param[in] flags Special options for this operation. This parameter"] - #[doc = " must be set to 0 or by bitwise OR'ing together one or more of the"] - #[doc = " values described here."] - #[doc = "
    "] - #[doc = "\t
  • #MDB_CP_COMPACT - Perform compaction while copying: omit free"] - #[doc = "\t\tpages and sequentially renumber all pages in output. This option"] - #[doc = "\t\tconsumes more CPU and runs more slowly than the default."] - #[doc = "\t\tCurrently it fails if the environment has suffered a page leak."] - #[doc = "
"] - #[doc = " @return A non-zero error value on failure and 0 on success."] + #[doc = "Copy an LMDB environment to the specified path, with options.\n\nThis function may be used to make a backup of an existing environment.\nNo lockfile is created, since it gets recreated at need.\nparallel with write transactions, because it employs a read-only\ntransaction. See long-lived transactions under [`caveats_sec`]\nmust have already been opened successfully.\ndirectory must already exist and be writable but must otherwise be\nempty.\nmust be set to 0 or by bitwise OR'ing together one or more of the\nvalues described here.\n
    \n
  • #MDB_CP_COMPACT - Perform compaction while copying: omit free\npages and sequentially renumber all pages in output. This option\nconsumes more CPU and runs more slowly than the default.\nCurrently it fails if the environment has suffered a page leak.\n
\n\nReturns:\n\n* A non-zero error value on failure and 0 on success.\n\n# Arguments\n\n* `env` - An environment handle returned by #mdb_env_create(). It [Direction: In]\n* `path` - The directory in which the copy will reside. This [Direction: In]\n* `flags` - Special options for this operation. This parameter [Direction: In]\n\n# Notes\n\n* This call can trigger significant file size growth if run in\n\n"] pub fn mdb_env_copy2( env: *mut MDB_env, path: *const ::libc::c_char, @@ -474,22 +232,7 @@ extern "C" { ) -> ::libc::c_int; } extern "C" { - #[doc = " @brief Copy an LMDB environment to the specified file descriptor,"] - #[doc = "\twith options."] - #[doc = ""] - #[doc = " This function may be used to make a backup of an existing environment."] - #[doc = " No lockfile is created, since it gets recreated at need. See"] - #[doc = " #mdb_env_copy2() for further details."] - #[doc = " @note This call can trigger significant file size growth if run in"] - #[doc = " parallel with write transactions, because it employs a read-only"] - #[doc = " transaction. See long-lived transactions under @ref caveats_sec."] - #[doc = " @param[in] env An environment handle returned by #mdb_env_create(). It"] - #[doc = " must have already been opened successfully."] - #[doc = " @param[in] fd The filedescriptor to write the copy to. It must"] - #[doc = " have already been opened for Write access."] - #[doc = " @param[in] flags Special options for this operation."] - #[doc = " See #mdb_env_copy2() for options."] - #[doc = " @return A non-zero error value on failure and 0 on success."] + #[doc = "Copy an LMDB environment to the specified file descriptor,\n\nwith options.\nThis function may be used to make a backup of an existing environment.\nNo lockfile is created, since it gets recreated at need. See\n#mdb_env_copy2() for further details.\nparallel with write transactions, because it employs a read-only\ntransaction. See long-lived transactions under [`caveats_sec`]\nmust have already been opened successfully.\nhave already been opened for Write access.\nSee #mdb_env_copy2() for options.\n\nReturns:\n\n* A non-zero error value on failure and 0 on success.\n\n# Arguments\n\n* `env` - An environment handle returned by #mdb_env_create(). It [Direction: In]\n* `fd` - The filedescriptor to write the copy to. It must [Direction: In]\n* `flags` - Special options for this operation. [Direction: In]\n\n# Notes\n\n* This call can trigger significant file size growth if run in\n\n"] pub fn mdb_env_copyfd2( env: *mut MDB_env, fd: mdb_filehandle_t, @@ -497,66 +240,23 @@ extern "C" { ) -> ::libc::c_int; } extern "C" { - #[doc = " @brief Return statistics about the LMDB environment."] - #[doc = ""] - #[doc = " @param[in] env An environment handle returned by #mdb_env_create()"] - #[doc = " @param[out] stat The address of an #MDB_stat structure"] - #[doc = " \twhere the statistics will be copied"] + #[doc = "Return statistics about the LMDB environment.\n\nwhere the statistics will be copied\n\n# Arguments\n\n* `env` - An environment handle returned by #mdb_env_create() [Direction: In]\n* `stat` - The address of an #MDB_stat structure [Direction: In, Out]\n\n"] pub fn mdb_env_stat(env: *mut MDB_env, stat: *mut MDB_stat) -> ::libc::c_int; } extern "C" { - #[doc = " @brief Return information about the LMDB environment."] - #[doc = ""] - #[doc = " @param[in] env An environment handle returned by #mdb_env_create()"] - #[doc = " @param[out] stat The address of an #MDB_envinfo structure"] - #[doc = " \twhere the information will be copied"] + #[doc = "Return information about the LMDB environment.\n\nwhere the information will be copied\n\n# Arguments\n\n* `env` - An environment handle returned by #mdb_env_create() [Direction: In]\n* `stat` - The address of an #MDB_envinfo structure [Direction: In, Out]\n\n"] pub fn mdb_env_info(env: *mut MDB_env, stat: *mut MDB_envinfo) -> ::libc::c_int; } extern "C" { - #[doc = " @brief Flush the data buffers to disk."] - #[doc = ""] - #[doc = " Data is always written to disk when #mdb_txn_commit() is called,"] - #[doc = " but the operating system may keep it buffered. LMDB always flushes"] - #[doc = " the OS buffers upon commit as well, unless the environment was"] - #[doc = " opened with #MDB_NOSYNC or in part #MDB_NOMETASYNC. This call is"] - #[doc = " not valid if the environment was opened with #MDB_RDONLY."] - #[doc = " @param[in] env An environment handle returned by #mdb_env_create()"] - #[doc = " @param[in] force If non-zero, force a synchronous flush. Otherwise"] - #[doc = " if the environment has the #MDB_NOSYNC flag set the flushes"] - #[doc = "\twill be omitted, and with #MDB_MAPASYNC they will be asynchronous."] - #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] - #[doc = " errors are:"] - #[doc = "
    "] - #[doc = "\t
  • EACCES - the environment is read-only."] - #[doc = "\t
  • EINVAL - an invalid parameter was specified."] - #[doc = "\t
  • EIO - an error occurred during synchronization."] - #[doc = "
"] + #[doc = "Flush the data buffers to disk.\n\nData is always written to disk when #mdb_txn_commit() is called,\nbut the operating system may keep it buffered. LMDB always flushes\nthe OS buffers upon commit as well, unless the environment was\nopened with #MDB_NOSYNC or in part #MDB_NOMETASYNC. This call is\nnot valid if the environment was opened with #MDB_RDONLY.\nif the environment has the #MDB_NOSYNC flag set the flushes\nwill be omitted, and with #MDB_MAPASYNC they will be asynchronous.\nerrors are:\n
    \n
  • EACCES - the environment is read-only.\n
  • EINVAL - an invalid parameter was specified.\n
  • EIO - an error occurred during synchronization.\n
\n\nReturns:\n\n* A non-zero error value on failure and 0 on success. Some possible\n\n# Arguments\n\n* `env` - An environment handle returned by #mdb_env_create() [Direction: In]\n* `force` - If non-zero, force a synchronous flush. Otherwise [Direction: In]\n\n"] pub fn mdb_env_sync(env: *mut MDB_env, force: ::libc::c_int) -> ::libc::c_int; } extern "C" { - #[doc = " @brief Close the environment and release the memory map."] - #[doc = ""] - #[doc = " Only a single thread may call this function. All transactions, databases,"] - #[doc = " and cursors must already be closed before calling this function. Attempts to"] - #[doc = " use any such handles after calling this function will cause a SIGSEGV."] - #[doc = " The environment handle will be freed and must not be used again after this call."] - #[doc = " @param[in] env An environment handle returned by #mdb_env_create()"] + #[doc = "Close the environment and release the memory map.\n\nOnly a single thread may call this function. All transactions, databases,\nand cursors must already be closed before calling this function. Attempts to\nuse any such handles after calling this function will cause a SIGSEGV.\nThe environment handle will be freed and must not be used again after this call.\n\n# Arguments\n\n* `env` - An environment handle returned by #mdb_env_create() [Direction: In]\n\n"] pub fn mdb_env_close(env: *mut MDB_env); } extern "C" { - #[doc = " @brief Set environment flags."] - #[doc = ""] - #[doc = " This may be used to set some flags in addition to those from"] - #[doc = " #mdb_env_open(), or to unset these flags. If several threads"] - #[doc = " change the flags at the same time, the result is undefined."] - #[doc = " @param[in] env An environment handle returned by #mdb_env_create()"] - #[doc = " @param[in] flags The flags to change, bitwise OR'ed together"] - #[doc = " @param[in] onoff A non-zero value sets the flags, zero clears them."] - #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] - #[doc = " errors are:"] - #[doc = "
    "] - #[doc = "\t
  • EINVAL - an invalid parameter was specified."] - #[doc = "
"] + #[doc = "Set environment flags.\n\nThis may be used to set some flags in addition to those from\n#mdb_env_open(), or to unset these flags. If several threads\nchange the flags at the same time, the result is undefined.\nerrors are:\n
    \n
  • EINVAL - an invalid parameter was specified.\n
\n\nReturns:\n\n* A non-zero error value on failure and 0 on success. Some possible\n\n# Arguments\n\n* `env` - An environment handle returned by #mdb_env_create() [Direction: In]\n* `flags` - The flags to change, bitwise OR'ed together [Direction: In]\n* `onoff` - A non-zero value sets the flags, zero clears them. [Direction: In]\n\n"] pub fn mdb_env_set_flags( env: *mut MDB_env, flags: ::libc::c_uint, @@ -564,193 +264,59 @@ extern "C" { ) -> ::libc::c_int; } extern "C" { - #[doc = " @brief Get environment flags."] - #[doc = ""] - #[doc = " @param[in] env An environment handle returned by #mdb_env_create()"] - #[doc = " @param[out] flags The address of an integer to store the flags"] - #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] - #[doc = " errors are:"] - #[doc = "
    "] - #[doc = "\t
  • EINVAL - an invalid parameter was specified."] - #[doc = "
"] + #[doc = "Get environment flags.\n\nerrors are:\n
    \n
  • EINVAL - an invalid parameter was specified.\n
\n\nReturns:\n\n* A non-zero error value on failure and 0 on success. Some possible\n\n# Arguments\n\n* `env` - An environment handle returned by #mdb_env_create() [Direction: In]\n* `flags` - The address of an integer to store the flags [Direction: In, Out]\n\n"] pub fn mdb_env_get_flags(env: *mut MDB_env, flags: *mut ::libc::c_uint) -> ::libc::c_int; } extern "C" { - #[doc = " @brief Return the path that was used in #mdb_env_open()."] - #[doc = ""] - #[doc = " @param[in] env An environment handle returned by #mdb_env_create()"] - #[doc = " @param[out] path Address of a string pointer to contain the path. This"] - #[doc = " is the actual string in the environment, not a copy. It should not be"] - #[doc = " altered in any way."] - #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] - #[doc = " errors are:"] - #[doc = "
    "] - #[doc = "\t
  • EINVAL - an invalid parameter was specified."] - #[doc = "
"] + #[doc = "Return the path that was used in #mdb_env_open().\n\nis the actual string in the environment, not a copy. It should not be\naltered in any way.\nerrors are:\n
    \n
  • EINVAL - an invalid parameter was specified.\n
\n\nReturns:\n\n* A non-zero error value on failure and 0 on success. Some possible\n\n# Arguments\n\n* `env` - An environment handle returned by #mdb_env_create() [Direction: In]\n* `path` - Address of a string pointer to contain the path. This [Direction: In, Out]\n\n"] pub fn mdb_env_get_path(env: *mut MDB_env, path: *mut *const ::libc::c_char) -> ::libc::c_int; } extern "C" { - #[doc = " @brief Return the filedescriptor for the given environment."] - #[doc = ""] - #[doc = " This function may be called after fork(), so the descriptor can be"] - #[doc = " closed before exec*(). Other LMDB file descriptors have FD_CLOEXEC."] - #[doc = " (Until LMDB 0.9.18, only the lockfile had that.)"] - #[doc = ""] - #[doc = " @param[in] env An environment handle returned by #mdb_env_create()"] - #[doc = " @param[out] fd Address of a mdb_filehandle_t to contain the descriptor."] - #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] - #[doc = " errors are:"] - #[doc = "
    "] - #[doc = "\t
  • EINVAL - an invalid parameter was specified."] - #[doc = "
"] + #[doc = "Return the filedescriptor for the given environment.\n\nThis function may be called after fork(), so the descriptor can be\nclosed before exec*(). Other LMDB file descriptors have FD_CLOEXEC.\n(Until LMDB 0.9.18, only the lockfile had that.)\nerrors are:\n
    \n
  • EINVAL - an invalid parameter was specified.\n
\n\nReturns:\n\n* A non-zero error value on failure and 0 on success. Some possible\n\n# Arguments\n\n* `env` - An environment handle returned by #mdb_env_create() [Direction: In]\n* `fd` - Address of a mdb_filehandle_t to contain the descriptor. [Direction: In, Out]\n\n"] pub fn mdb_env_get_fd(env: *mut MDB_env, fd: *mut mdb_filehandle_t) -> ::libc::c_int; } extern "C" { - #[doc = " @brief Set the size of the memory map to use for this environment."] - #[doc = ""] - #[doc = " The size should be a multiple of the OS page size. The default is"] - #[doc = " 10485760 bytes. The size of the memory map is also the maximum size"] - #[doc = " of the database. The value should be chosen as large as possible,"] - #[doc = " to accommodate future growth of the database."] - #[doc = " This function should be called after #mdb_env_create() and before #mdb_env_open()."] - #[doc = " It may be called at later times if no transactions are active in"] - #[doc = " this process. Note that the library does not check for this condition,"] - #[doc = " the caller must ensure it explicitly."] - #[doc = ""] - #[doc = " The new size takes effect immediately for the current process but"] - #[doc = " will not be persisted to any others until a write transaction has been"] - #[doc = " committed by the current process. Also, only mapsize increases are"] - #[doc = " persisted into the environment."] - #[doc = ""] - #[doc = " If the mapsize is increased by another process, and data has grown"] - #[doc = " beyond the range of the current mapsize, #mdb_txn_begin() will"] - #[doc = " return #MDB_MAP_RESIZED. This function may be called with a size"] - #[doc = " of zero to adopt the new size."] - #[doc = ""] - #[doc = " Any attempt to set a size smaller than the space already consumed"] - #[doc = " by the environment will be silently changed to the current size of the used space."] - #[doc = " @param[in] env An environment handle returned by #mdb_env_create()"] - #[doc = " @param[in] size The size in bytes"] - #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] - #[doc = " errors are:"] - #[doc = "
    "] - #[doc = "\t
  • EINVAL - an invalid parameter was specified, or the environment has"] - #[doc = " \tan active write transaction."] - #[doc = "
"] + #[doc = "Set the size of the memory map to use for this environment.\n\nThe size should be a multiple of the OS page size. The default is\n10485760 bytes. The size of the memory map is also the maximum size\nof the database. The value should be chosen as large as possible,\nto accommodate future growth of the database.\nThis function should be called after #mdb_env_create() and before #mdb_env_open().\nIt may be called at later times if no transactions are active in\nthis process. Note that the library does not check for this condition,\nthe caller must ensure it explicitly.\nThe new size takes effect immediately for the current process but\nwill not be persisted to any others until a write transaction has been\ncommitted by the current process. Also, only mapsize increases are\npersisted into the environment.\nIf the mapsize is increased by another process, and data has grown\nbeyond the range of the current mapsize, #mdb_txn_begin() will\nreturn #MDB_MAP_RESIZED. This function may be called with a size\nof zero to adopt the new size.\nAny attempt to set a size smaller than the space already consumed\nby the environment will be silently changed to the current size of the used space.\nerrors are:\n
    \n
  • EINVAL - an invalid parameter was specified, or the environment has\nan active write transaction.\n
\n\nReturns:\n\n* A non-zero error value on failure and 0 on success. Some possible\n\n# Arguments\n\n* `env` - An environment handle returned by #mdb_env_create() [Direction: In]\n* `size` - The size in bytes [Direction: In]\n\n"] pub fn mdb_env_set_mapsize(env: *mut MDB_env, size: mdb_size_t) -> ::libc::c_int; } extern "C" { - #[doc = " @brief Set the size of DB pages in bytes."] - #[doc = ""] - #[doc = " The size defaults to the OS page size. Smaller or larger values may be"] - #[doc = " desired depending on the size of keys and values being used. Also, an"] - #[doc = " explicit size may need to be set when using filesystems like ZFS which"] - #[doc = " don't use the OS page size."] + #[doc = "Set the size of DB pages in bytes.\n\nThe size defaults to the OS page size. Smaller or larger values may be\ndesired depending on the size of keys and values being used. Also, an\nexplicit size may need to be set when using filesystems like ZFS which\ndon't use the OS page size.\n\n"] pub fn mdb_env_set_pagesize(env: *mut MDB_env, size: ::libc::c_int) -> ::libc::c_int; } extern "C" { - #[doc = " @brief Set the maximum number of threads/reader slots for the environment."] - #[doc = ""] - #[doc = " This defines the number of slots in the lock table that is used to track readers in the"] - #[doc = " the environment. The default is 126."] - #[doc = " Starting a read-only transaction normally ties a lock table slot to the"] - #[doc = " current thread until the environment closes or the thread exits. If"] - #[doc = " MDB_NOTLS is in use, #mdb_txn_begin() instead ties the slot to the"] - #[doc = " MDB_txn object until it or the #MDB_env object is destroyed."] - #[doc = " This function may only be called after #mdb_env_create() and before #mdb_env_open()."] - #[doc = " @param[in] env An environment handle returned by #mdb_env_create()"] - #[doc = " @param[in] readers The maximum number of reader lock table slots"] - #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] - #[doc = " errors are:"] - #[doc = "
    "] - #[doc = "\t
  • EINVAL - an invalid parameter was specified, or the environment is already open."] - #[doc = "
"] + #[doc = "Set the maximum number of threads/reader slots for the environment.\n\nThis defines the number of slots in the lock table that is used to track readers in the\nthe environment. The default is 126.\nStarting a read-only transaction normally ties a lock table slot to the\ncurrent thread until the environment closes or the thread exits. If\nMDB_NOTLS is in use, #mdb_txn_begin() instead ties the slot to the\nMDB_txn object until it or the #MDB_env object is destroyed.\nThis function may only be called after #mdb_env_create() and before #mdb_env_open().\nerrors are:\n
    \n
  • EINVAL - an invalid parameter was specified, or the environment is already open.\n
\n\nReturns:\n\n* A non-zero error value on failure and 0 on success. Some possible\n\n# Arguments\n\n* `env` - An environment handle returned by #mdb_env_create() [Direction: In]\n* `readers` - The maximum number of reader lock table slots [Direction: In]\n\n"] pub fn mdb_env_set_maxreaders(env: *mut MDB_env, readers: ::libc::c_uint) -> ::libc::c_int; } extern "C" { - #[doc = " @brief Get the maximum number of threads/reader slots for the environment."] - #[doc = ""] - #[doc = " @param[in] env An environment handle returned by #mdb_env_create()"] - #[doc = " @param[out] readers Address of an integer to store the number of readers"] - #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] - #[doc = " errors are:"] - #[doc = "
    "] - #[doc = "\t
  • EINVAL - an invalid parameter was specified."] - #[doc = "
"] + #[doc = "Get the maximum number of threads/reader slots for the environment.\n\nerrors are:\n
    \n
  • EINVAL - an invalid parameter was specified.\n
\n\nReturns:\n\n* A non-zero error value on failure and 0 on success. Some possible\n\n# Arguments\n\n* `env` - An environment handle returned by #mdb_env_create() [Direction: In]\n* `readers` - Address of an integer to store the number of readers [Direction: In, Out]\n\n"] pub fn mdb_env_get_maxreaders(env: *mut MDB_env, readers: *mut ::libc::c_uint) -> ::libc::c_int; } extern "C" { - #[doc = " @brief Set the maximum number of named databases for the environment."] - #[doc = ""] - #[doc = " This function is only needed if multiple databases will be used in the"] - #[doc = " environment. Simpler applications that use the environment as a single"] - #[doc = " unnamed database can ignore this option."] - #[doc = " This function may only be called after #mdb_env_create() and before #mdb_env_open()."] - #[doc = ""] - #[doc = " Currently a moderate number of slots are cheap but a huge number gets"] - #[doc = " expensive: 7-120 words per transaction, and every #mdb_dbi_open()"] - #[doc = " does a linear search of the opened slots."] - #[doc = " @param[in] env An environment handle returned by #mdb_env_create()"] - #[doc = " @param[in] dbs The maximum number of databases"] - #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] - #[doc = " errors are:"] - #[doc = "
    "] - #[doc = "\t
  • EINVAL - an invalid parameter was specified, or the environment is already open."] - #[doc = "
"] + #[doc = "Set the maximum number of named databases for the environment.\n\nThis function is only needed if multiple databases will be used in the\nenvironment. Simpler applications that use the environment as a single\nunnamed database can ignore this option.\nThis function may only be called after #mdb_env_create() and before #mdb_env_open().\nCurrently a moderate number of slots are cheap but a huge number gets\nexpensive: 7-120 words per transaction, and every #mdb_dbi_open()\ndoes a linear search of the opened slots.\nerrors are:\n
    \n
  • EINVAL - an invalid parameter was specified, or the environment is already open.\n
\n\nReturns:\n\n* A non-zero error value on failure and 0 on success. Some possible\n\n# Arguments\n\n* `env` - An environment handle returned by #mdb_env_create() [Direction: In]\n* `dbs` - The maximum number of databases [Direction: In]\n\n"] pub fn mdb_env_set_maxdbs(env: *mut MDB_env, dbs: MDB_dbi) -> ::libc::c_int; } extern "C" { - #[doc = " @brief Get the maximum size of keys and #MDB_DUPSORT data we can write."] - #[doc = ""] - #[doc = " Depends on the compile-time constant #MDB_MAXKEYSIZE. Default 511."] - #[doc = " See @ref MDB_val."] - #[doc = " @param[in] env An environment handle returned by #mdb_env_create()"] - #[doc = " @return The maximum size of a key we can write"] + #[doc = "Get the maximum size of keys and #MDB_DUPSORT data we can write.\n\nDepends on the compile-time constant #MDB_MAXKEYSIZE. Default 511.\nSee [`MDB_val`]\n\nReturns:\n\n* The maximum size of a key we can write\n\n# Arguments\n\n* `env` - An environment handle returned by #mdb_env_create() [Direction: In]\n\n"] pub fn mdb_env_get_maxkeysize(env: *mut MDB_env) -> ::libc::c_int; } extern "C" { - #[doc = " @brief Set application information associated with the #MDB_env."] - #[doc = ""] - #[doc = " @param[in] env An environment handle returned by #mdb_env_create()"] - #[doc = " @param[in] ctx An arbitrary pointer for whatever the application needs."] - #[doc = " @return A non-zero error value on failure and 0 on success."] + #[doc = "Set application information associated with the #MDB_env.\n\nReturns:\n\n* A non-zero error value on failure and 0 on success.\n\n# Arguments\n\n* `env` - An environment handle returned by #mdb_env_create() [Direction: In]\n* `ctx` - An arbitrary pointer for whatever the application needs. [Direction: In]\n\n"] pub fn mdb_env_set_userctx(env: *mut MDB_env, ctx: *mut ::libc::c_void) -> ::libc::c_int; } extern "C" { - #[doc = " @brief Get the application information associated with the #MDB_env."] - #[doc = ""] - #[doc = " @param[in] env An environment handle returned by #mdb_env_create()"] - #[doc = " @return The pointer set by #mdb_env_set_userctx()."] + #[doc = "Get the application information associated with the #MDB_env.\n\nReturns:\n\n* The pointer set by #mdb_env_set_userctx().\n\n# Arguments\n\n* `env` - An environment handle returned by #mdb_env_create() [Direction: In]\n\n"] pub fn mdb_env_get_userctx(env: *mut MDB_env) -> *mut ::libc::c_void; } -#[doc = " @brief A callback function for most LMDB assert() failures,"] -#[doc = " called before printing the message and aborting."] -#[doc = ""] -#[doc = " @param[in] env An environment handle returned by #mdb_env_create()."] -#[doc = " @param[in] msg The assertion message, not including newline."] +#[doc = "A callback function for most LMDB assert() failures,\n\ncalled before printing the message and aborting.\n\n# Arguments\n\n* `env` - An environment handle returned by #mdb_env_create(). [Direction: In]\n* `msg` - The assertion message, not including newline. [Direction: In]\n\n"] pub type MDB_assert_func = ::std::option::Option; extern "C" { - #[doc = " Set or reset the assert() callback of the environment."] - #[doc = " Disabled if liblmdb is built with NDEBUG."] - #[doc = " @note This hack should become obsolete as lmdb's error handling matures."] - #[doc = " @param[in] env An environment handle returned by #mdb_env_create()."] - #[doc = " @param[in] func An #MDB_assert_func function, or 0."] - #[doc = " @return A non-zero error value on failure and 0 on success."] + #[doc = "Set or reset the assert() callback of the environment.\nDisabled if liblmdb is built with NDEBUG.\n\nReturns:\n\n* A non-zero error value on failure and 0 on success.\n\n# Arguments\n\n* `env` - An environment handle returned by #mdb_env_create(). [Direction: In]\n* `func` - An #MDB_assert_func function, or 0. [Direction: In]\n\n# Notes\n\n* This hack should become obsolete as lmdb's error handling matures.\n\n"] pub fn mdb_env_set_assert(env: *mut MDB_env, func: MDB_assert_func) -> ::libc::c_int; } extern "C" { - #[doc = " @brief Set encryption on an environment."] - #[doc = ""] - #[doc = " This must be called before #mdb_env_open()."] - #[doc = " It implicitly sets #MDB_REMAP_CHUNKS on the env."] - #[doc = " @param[in] env An environment handle returned by #mdb_env_create()."] - #[doc = " @param[in] func An #MDB_enc_func function."] - #[doc = " @param[in] key The encryption key."] - #[doc = " @param[in] size The size of authentication data in bytes, if any."] - #[doc = " Set this to zero for unauthenticated encryption mechanisms."] - #[doc = " @return A non-zero error value on failure and 0 on success."] + #[doc = "Set encryption on an environment.\n\nThis must be called before #mdb_env_open().\nIt implicitly sets #MDB_REMAP_CHUNKS on the env.\nSet this to zero for unauthenticated encryption mechanisms.\n\nReturns:\n\n* A non-zero error value on failure and 0 on success.\n\n# Arguments\n\n* `env` - An environment handle returned by #mdb_env_create(). [Direction: In]\n* `func` - An #MDB_enc_func function. [Direction: In]\n* `key` - The encryption key. [Direction: In]\n* `size` - The size of authentication data in bytes, if any. [Direction: In]\n\n"] pub fn mdb_env_set_encrypt( env: *mut MDB_env, func: MDB_enc_func, @@ -759,13 +325,7 @@ extern "C" { ) -> ::libc::c_int; } extern "C" { - #[doc = " @brief Set checksums on an environment."] - #[doc = ""] - #[doc = " This must be called before #mdb_env_open()."] - #[doc = " @param[in] env An environment handle returned by #mdb_env_create()."] - #[doc = " @param[in] func An #MDB_sum_func function."] - #[doc = " @param[in] size The size of computed checksum values, in bytes."] - #[doc = " @return A non-zero error value on failure and 0 on success."] + #[doc = "Set checksums on an environment.\n\nThis must be called before #mdb_env_open().\n\nReturns:\n\n* A non-zero error value on failure and 0 on success.\n\n# Arguments\n\n* `env` - An environment handle returned by #mdb_env_create(). [Direction: In]\n* `func` - An #MDB_sum_func function. [Direction: In]\n* `size` - The size of computed checksum values, in bytes. [Direction: In]\n\n"] pub fn mdb_env_set_checksum( env: *mut MDB_env, func: MDB_sum_func, @@ -773,43 +333,7 @@ extern "C" { ) -> ::libc::c_int; } extern "C" { - #[doc = " @brief Create a transaction for use with the environment."] - #[doc = ""] - #[doc = " The transaction handle may be discarded using #mdb_txn_abort() or #mdb_txn_commit()."] - #[doc = " @note A transaction and its cursors must only be used by a single"] - #[doc = " thread, and a thread may only have a single transaction at a time."] - #[doc = " If #MDB_NOTLS is in use, this does not apply to read-only transactions."] - #[doc = " @note Cursors may not span transactions."] - #[doc = " @param[in] env An environment handle returned by #mdb_env_create()"] - #[doc = " @param[in] parent If this parameter is non-NULL, the new transaction"] - #[doc = " will be a nested transaction, with the transaction indicated by \\b parent"] - #[doc = " as its parent. Transactions may be nested to any level. A parent"] - #[doc = " transaction and its cursors may not issue any other operations than"] - #[doc = " mdb_txn_commit and mdb_txn_abort while it has active child transactions."] - #[doc = " @param[in] flags Special options for this transaction. This parameter"] - #[doc = " must be set to 0 or by bitwise OR'ing together one or more of the"] - #[doc = " values described here."] - #[doc = "
    "] - #[doc = "\t
  • #MDB_RDONLY"] - #[doc = "\t\tThis transaction will not perform any write operations."] - #[doc = "\t
  • #MDB_NOSYNC"] - #[doc = "\t\tDon't flush system buffers to disk when committing this transaction."] - #[doc = "\t
  • #MDB_NOMETASYNC"] - #[doc = "\t\tFlush system buffers but omit metadata flush when committing this transaction."] - #[doc = "
"] - #[doc = " @param[out] txn Address where the new #MDB_txn handle will be stored"] - #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] - #[doc = " errors are:"] - #[doc = "
    "] - #[doc = "\t
  • #MDB_PANIC - a fatal error occurred earlier and the environment"] - #[doc = "\t\tmust be shut down."] - #[doc = "\t
  • #MDB_MAP_RESIZED - another process wrote data beyond this MDB_env's"] - #[doc = "\t\tmapsize and this environment's map must be resized as well."] - #[doc = "\t\tSee #mdb_env_set_mapsize()."] - #[doc = "\t
  • #MDB_READERS_FULL - a read-only transaction was requested and"] - #[doc = "\t\tthe reader lock table is full. See #mdb_env_set_maxreaders()."] - #[doc = "\t
  • ENOMEM - out of memory."] - #[doc = "
"] + #[doc = "Create a transaction for use with the environment.\n\nThe transaction handle may be discarded using #mdb_txn_abort() or #mdb_txn_commit().\nthread, and a thread may only have a single transaction at a time.\nIf #MDB_NOTLS is in use, this does not apply to read-only transactions.\nwill be a nested transaction, with the transaction indicated by \\b parent\nas its parent. Transactions may be nested to any level. A parent\ntransaction and its cursors may not issue any other operations than\nmdb_txn_commit and mdb_txn_abort while it has active child transactions.\nmust be set to 0 or by bitwise OR'ing together one or more of the\nvalues described here.\n
    \n
  • #MDB_RDONLY\nThis transaction will not perform any write operations.\n
  • #MDB_NOSYNC\nDon't flush system buffers to disk when committing this transaction.\n
  • #MDB_NOMETASYNC\nFlush system buffers but omit metadata flush when committing this transaction.\n
\nerrors are:\n
    \n
  • #MDB_PANIC - a fatal error occurred earlier and the environment\nmust be shut down.\n
  • #MDB_MAP_RESIZED - another process wrote data beyond this MDB_env's\nmapsize and this environment's map must be resized as well.\nSee #mdb_env_set_mapsize().\n
  • #MDB_READERS_FULL - a read-only transaction was requested and\nthe reader lock table is full. See #mdb_env_set_maxreaders().\n
  • ENOMEM - out of memory.\n
\n\nReturns:\n\n* A non-zero error value on failure and 0 on success. Some possible\n\n# Arguments\n\n* `env` - An environment handle returned by #mdb_env_create() [Direction: In]\n* `parent` - If this parameter is non-NULL, the new transaction [Direction: In]\n* `flags` - Special options for this transaction. This parameter [Direction: In]\n* `txn` - Address where the new #MDB_txn handle will be stored [Direction: In, Out]\n\n# Notes\n\n* A transaction and its cursors must only be used by a single\n* Cursors may not span transactions.\n\n"] pub fn mdb_txn_begin( env: *mut MDB_env, parent: *mut MDB_txn, @@ -818,156 +342,31 @@ extern "C" { ) -> ::libc::c_int; } extern "C" { - #[doc = " @brief Returns the transaction's #MDB_env"] - #[doc = ""] - #[doc = " @param[in] txn A transaction handle returned by #mdb_txn_begin()"] + #[doc = "Returns the transaction's #MDB_env\n\n# Arguments\n\n* `txn` - A transaction handle returned by #mdb_txn_begin() [Direction: In]\n\n"] pub fn mdb_txn_env(txn: *mut MDB_txn) -> *mut MDB_env; } extern "C" { - #[doc = " @brief Return the transaction's ID."] - #[doc = ""] - #[doc = " This returns the identifier associated with this transaction. For a"] - #[doc = " read-only transaction, this corresponds to the snapshot being read;"] - #[doc = " concurrent readers will frequently have the same transaction ID."] - #[doc = ""] - #[doc = " @param[in] txn A transaction handle returned by #mdb_txn_begin()"] - #[doc = " @return A transaction ID, valid if input is an active transaction."] + #[doc = "Return the transaction's ID.\n\nThis returns the identifier associated with this transaction. For a\nread-only transaction, this corresponds to the snapshot being read;\nconcurrent readers will frequently have the same transaction ID.\n\nReturns:\n\n* A transaction ID, valid if input is an active transaction.\n\n# Arguments\n\n* `txn` - A transaction handle returned by #mdb_txn_begin() [Direction: In]\n\n"] pub fn mdb_txn_id(txn: *mut MDB_txn) -> mdb_size_t; } extern "C" { - #[doc = " @brief Commit all the operations of a transaction into the database."] - #[doc = ""] - #[doc = " The transaction handle is freed. It and its cursors must not be used"] - #[doc = " again after this call, except with #mdb_cursor_renew()."] - #[doc = " @note Earlier documentation incorrectly said all cursors would be freed."] - #[doc = " Only write-transactions free cursors."] - #[doc = " @param[in] txn A transaction handle returned by #mdb_txn_begin()"] - #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] - #[doc = " errors are:"] - #[doc = "
    "] - #[doc = "\t
  • EINVAL - an invalid parameter was specified."] - #[doc = "\t
  • ENOSPC - no more disk space."] - #[doc = "\t
  • EIO - a low-level I/O error occurred while writing."] - #[doc = "\t
  • ENOMEM - out of memory."] - #[doc = "
"] + #[doc = "Commit all the operations of a transaction into the database.\n\nThe transaction handle is freed. It and its cursors must not be used\nagain after this call, except with #mdb_cursor_renew().\nOnly write-transactions free cursors.\nerrors are:\n
    \n
  • EINVAL - an invalid parameter was specified.\n
  • ENOSPC - no more disk space.\n
  • EIO - a low-level I/O error occurred while writing.\n
  • ENOMEM - out of memory.\n
\n\nReturns:\n\n* A non-zero error value on failure and 0 on success. Some possible\n\n# Arguments\n\n* `txn` - A transaction handle returned by #mdb_txn_begin() [Direction: In]\n\n# Notes\n\n* Earlier documentation incorrectly said all cursors would be freed.\n\n"] pub fn mdb_txn_commit(txn: *mut MDB_txn) -> ::libc::c_int; } extern "C" { - #[doc = " @brief Abandon all the operations of the transaction instead of saving them."] - #[doc = ""] - #[doc = " The transaction handle is freed. It and its cursors must not be used"] - #[doc = " again after this call, except with #mdb_cursor_renew()."] - #[doc = " @note Earlier documentation incorrectly said all cursors would be freed."] - #[doc = " Only write-transactions free cursors."] - #[doc = " @param[in] txn A transaction handle returned by #mdb_txn_begin()"] + #[doc = "Abandon all the operations of the transaction instead of saving them.\n\nThe transaction handle is freed. It and its cursors must not be used\nagain after this call, except with #mdb_cursor_renew().\nOnly write-transactions free cursors.\n\n# Arguments\n\n* `txn` - A transaction handle returned by #mdb_txn_begin() [Direction: In]\n\n# Notes\n\n* Earlier documentation incorrectly said all cursors would be freed.\n\n"] pub fn mdb_txn_abort(txn: *mut MDB_txn); } extern "C" { - #[doc = " @brief Reset a read-only transaction."] - #[doc = ""] - #[doc = " Abort the transaction like #mdb_txn_abort(), but keep the transaction"] - #[doc = " handle. #mdb_txn_renew() may reuse the handle. This saves allocation"] - #[doc = " overhead if the process will start a new read-only transaction soon,"] - #[doc = " and also locking overhead if #MDB_NOTLS is in use. The reader table"] - #[doc = " lock is released, but the table slot stays tied to its thread or"] - #[doc = " #MDB_txn. Use mdb_txn_abort() to discard a reset handle, and to free"] - #[doc = " its lock table slot if MDB_NOTLS is in use."] - #[doc = " Cursors opened within the transaction must not be used"] - #[doc = " again after this call, except with #mdb_cursor_renew()."] - #[doc = " Reader locks generally don't interfere with writers, but they keep old"] - #[doc = " versions of database pages allocated. Thus they prevent the old pages"] - #[doc = " from being reused when writers commit new data, and so under heavy load"] - #[doc = " the database size may grow much more rapidly than otherwise."] - #[doc = " @param[in] txn A transaction handle returned by #mdb_txn_begin()"] + #[doc = "Reset a read-only transaction.\n\nAbort the transaction like #mdb_txn_abort(), but keep the transaction\nhandle. #mdb_txn_renew() may reuse the handle. This saves allocation\noverhead if the process will start a new read-only transaction soon,\nand also locking overhead if #MDB_NOTLS is in use. The reader table\nlock is released, but the table slot stays tied to its thread or\n#MDB_txn. Use mdb_txn_abort() to discard a reset handle, and to free\nits lock table slot if MDB_NOTLS is in use.\nCursors opened within the transaction must not be used\nagain after this call, except with #mdb_cursor_renew().\nReader locks generally don't interfere with writers, but they keep old\nversions of database pages allocated. Thus they prevent the old pages\nfrom being reused when writers commit new data, and so under heavy load\nthe database size may grow much more rapidly than otherwise.\n\n# Arguments\n\n* `txn` - A transaction handle returned by #mdb_txn_begin() [Direction: In]\n\n"] pub fn mdb_txn_reset(txn: *mut MDB_txn); } extern "C" { - #[doc = " @brief Renew a read-only transaction."] - #[doc = ""] - #[doc = " This acquires a new reader lock for a transaction handle that had been"] - #[doc = " released by #mdb_txn_reset(). It must be called before a reset transaction"] - #[doc = " may be used again."] - #[doc = " @param[in] txn A transaction handle returned by #mdb_txn_begin()"] - #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] - #[doc = " errors are:"] - #[doc = "
    "] - #[doc = "\t
  • #MDB_PANIC - a fatal error occurred earlier and the environment"] - #[doc = "\t\tmust be shut down."] - #[doc = "\t
  • EINVAL - an invalid parameter was specified."] - #[doc = "
"] + #[doc = "Renew a read-only transaction.\n\nThis acquires a new reader lock for a transaction handle that had been\nreleased by #mdb_txn_reset(). It must be called before a reset transaction\nmay be used again.\nerrors are:\n
    \n
  • #MDB_PANIC - a fatal error occurred earlier and the environment\nmust be shut down.\n
  • EINVAL - an invalid parameter was specified.\n
\n\nReturns:\n\n* A non-zero error value on failure and 0 on success. Some possible\n\n# Arguments\n\n* `txn` - A transaction handle returned by #mdb_txn_begin() [Direction: In]\n\n"] pub fn mdb_txn_renew(txn: *mut MDB_txn) -> ::libc::c_int; } extern "C" { - #[doc = " @brief Open a database in the environment."] - #[doc = ""] - #[doc = " A database handle denotes the name and parameters of a database,"] - #[doc = " independently of whether such a database exists."] - #[doc = " The database handle may be discarded by calling #mdb_dbi_close()."] - #[doc = " The old database handle is returned if the database was already open."] - #[doc = " The handle may only be closed once."] - #[doc = ""] - #[doc = " The database handle will be private to the current transaction until"] - #[doc = " the transaction is successfully committed. If the transaction is"] - #[doc = " aborted the handle will be closed automatically."] - #[doc = " After a successful commit the handle will reside in the shared"] - #[doc = " environment, and may be used by other transactions."] - #[doc = ""] - #[doc = " This function must not be called from multiple concurrent"] - #[doc = " transactions in the same process. A transaction that uses"] - #[doc = " this function must finish (either commit or abort) before"] - #[doc = " any other transaction in the process may use this function."] - #[doc = ""] - #[doc = " To use named databases (with name != NULL), #mdb_env_set_maxdbs()"] - #[doc = " must be called before opening the environment. Database names are"] - #[doc = " keys in the unnamed database, and may be read but not written."] - #[doc = " @note Names are C strings and stored with their NUL terminator included."] - #[doc = " In LMDB 0.9 the NUL terminator was omitted."] - #[doc = ""] - #[doc = " @param[in] txn A transaction handle returned by #mdb_txn_begin()"] - #[doc = " @param[in] name The name of the database to open. If only a single"] - #[doc = " \tdatabase is needed in the environment, this value may be NULL."] - #[doc = " @param[in] flags Special options for this database. This parameter"] - #[doc = " must be set to 0 or by bitwise OR'ing together one or more of the"] - #[doc = " values described here."] - #[doc = "
    "] - #[doc = "\t
  • #MDB_REVERSEKEY"] - #[doc = "\t\tKeys are strings to be compared in reverse order, from the end"] - #[doc = "\t\tof the strings to the beginning. By default, Keys are treated as strings and"] - #[doc = "\t\tcompared from beginning to end."] - #[doc = "\t
  • #MDB_DUPSORT"] - #[doc = "\t\tDuplicate keys may be used in the database. (Or, from another perspective,"] - #[doc = "\t\tkeys may have multiple data items, stored in sorted order.) By default"] - #[doc = "\t\tkeys must be unique and may have only a single data item."] - #[doc = "\t
  • #MDB_INTEGERKEY"] - #[doc = "\t\tKeys are binary integers in native byte order, either unsigned int"] - #[doc = "\t\tor #mdb_size_t, and will be sorted as such."] - #[doc = "\t\t(lmdb expects 32-bit int <= size_t <= 32/64-bit mdb_size_t.)"] - #[doc = "\t\tThe keys must all be of the same size."] - #[doc = "\t
  • #MDB_DUPFIXED"] - #[doc = "\t\tThis flag may only be used in combination with #MDB_DUPSORT. This option"] - #[doc = "\t\ttells the library that the data items for this database are all the same"] - #[doc = "\t\tsize, which allows further optimizations in storage and retrieval. When"] - #[doc = "\t\tall data items are the same size, the #MDB_GET_MULTIPLE, #MDB_NEXT_MULTIPLE"] - #[doc = "\t\tand #MDB_PREV_MULTIPLE cursor operations may be used to retrieve multiple"] - #[doc = "\t\titems at once."] - #[doc = "\t
  • #MDB_INTEGERDUP"] - #[doc = "\t\tThis option specifies that duplicate data items are binary integers,"] - #[doc = "\t\tsimilar to #MDB_INTEGERKEY keys."] - #[doc = "\t
  • #MDB_REVERSEDUP"] - #[doc = "\t\tThis option specifies that duplicate data items should be compared as"] - #[doc = "\t\tstrings in reverse order."] - #[doc = "\t
  • #MDB_CREATE"] - #[doc = "\t\tCreate the named database if it doesn't exist. This option is not"] - #[doc = "\t\tallowed in a read-only transaction or a read-only environment."] - #[doc = "
"] - #[doc = " @param[out] dbi Address where the new #MDB_dbi handle will be stored"] - #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] - #[doc = " errors are:"] - #[doc = "
    "] - #[doc = "\t
  • #MDB_NOTFOUND - the specified database doesn't exist in the environment"] - #[doc = "\t\tand #MDB_CREATE was not specified."] - #[doc = "\t
  • #MDB_DBS_FULL - too many databases have been opened. See #mdb_env_set_maxdbs()."] - #[doc = "
"] + #[doc = "Open a database in the environment.\n\nA database handle denotes the name and parameters of a database,\nindependently of whether such a database exists.\nThe database handle may be discarded by calling #mdb_dbi_close().\nThe old database handle is returned if the database was already open.\nThe handle may only be closed once.\nThe database handle will be private to the current transaction until\nthe transaction is successfully committed. If the transaction is\naborted the handle will be closed automatically.\nAfter a successful commit the handle will reside in the shared\nenvironment, and may be used by other transactions.\nThis function must not be called from multiple concurrent\ntransactions in the same process. A transaction that uses\nthis function must finish (either commit or abort) before\nany other transaction in the process may use this function.\nTo use named databases (with name != NULL), #mdb_env_set_maxdbs()\nmust be called before opening the environment. Database names are\nkeys in the unnamed database, and may be read but not written.\nIn LMDB 0.9 the NUL terminator was omitted.\ndatabase is needed in the environment, this value may be NULL.\nmust be set to 0 or by bitwise OR'ing together one or more of the\nvalues described here.\n
    \n
  • #MDB_REVERSEKEY\nKeys are strings to be compared in reverse order, from the end\nof the strings to the beginning. By default, Keys are treated as strings and\ncompared from beginning to end.\n
  • #MDB_DUPSORT\nDuplicate keys may be used in the database. (Or, from another perspective,\nkeys may have multiple data items, stored in sorted order.) By default\nkeys must be unique and may have only a single data item.\n
  • #MDB_INTEGERKEY\nKeys are binary integers in native byte order, either unsigned int\nor #mdb_size_t, and will be sorted as such.\n(lmdb expects 32-bit int <= size_t <= 32/64-bit mdb_size_t.)\nThe keys must all be of the same size.\n
  • #MDB_DUPFIXED\nThis flag may only be used in combination with #MDB_DUPSORT. This option\ntells the library that the data items for this database are all the same\nsize, which allows further optimizations in storage and retrieval. When\nall data items are the same size, the #MDB_GET_MULTIPLE, #MDB_NEXT_MULTIPLE\nand #MDB_PREV_MULTIPLE cursor operations may be used to retrieve multiple\nitems at once.\n
  • #MDB_INTEGERDUP\nThis option specifies that duplicate data items are binary integers,\nsimilar to #MDB_INTEGERKEY keys.\n
  • #MDB_REVERSEDUP\nThis option specifies that duplicate data items should be compared as\nstrings in reverse order.\n
  • #MDB_CREATE\nCreate the named database if it doesn't exist. This option is not\nallowed in a read-only transaction or a read-only environment.\n
\nerrors are:\n
    \n
  • #MDB_NOTFOUND - the specified database doesn't exist in the environment\nand #MDB_CREATE was not specified.\n
  • #MDB_DBS_FULL - too many databases have been opened. See #mdb_env_set_maxdbs().\n
\n\nReturns:\n\n* A non-zero error value on failure and 0 on success. Some possible\n\n# Arguments\n\n* `txn` - A transaction handle returned by #mdb_txn_begin() [Direction: In]\n* `name` - The name of the database to open. If only a single [Direction: In]\n* `flags` - Special options for this database. This parameter [Direction: In]\n* `dbi` - Address where the new #MDB_dbi handle will be stored [Direction: In, Out]\n\n# Notes\n\n* Names are C strings and stored with their NUL terminator included.\n\n"] pub fn mdb_dbi_open( txn: *mut MDB_txn, name: *const ::libc::c_char, @@ -976,26 +375,11 @@ extern "C" { ) -> ::libc::c_int; } extern "C" { - #[doc = " @brief Retrieve statistics for a database."] - #[doc = ""] - #[doc = " @param[in] txn A transaction handle returned by #mdb_txn_begin()"] - #[doc = " @param[in] dbi A database handle returned by #mdb_dbi_open()"] - #[doc = " @param[out] stat The address of an #MDB_stat structure"] - #[doc = " \twhere the statistics will be copied"] - #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] - #[doc = " errors are:"] - #[doc = "
    "] - #[doc = "\t
  • EINVAL - an invalid parameter was specified."] - #[doc = "
"] + #[doc = "Retrieve statistics for a database.\n\nwhere the statistics will be copied\nerrors are:\n
    \n
  • EINVAL - an invalid parameter was specified.\n
\n\nReturns:\n\n* A non-zero error value on failure and 0 on success. Some possible\n\n# Arguments\n\n* `txn` - A transaction handle returned by #mdb_txn_begin() [Direction: In]\n* `dbi` - A database handle returned by #mdb_dbi_open() [Direction: In]\n* `stat` - The address of an #MDB_stat structure [Direction: In, Out]\n\n"] pub fn mdb_stat(txn: *mut MDB_txn, dbi: MDB_dbi, stat: *mut MDB_stat) -> ::libc::c_int; } extern "C" { - #[doc = " @brief Retrieve the DB flags for a database handle."] - #[doc = ""] - #[doc = " @param[in] txn A transaction handle returned by #mdb_txn_begin()"] - #[doc = " @param[in] dbi A database handle returned by #mdb_dbi_open()"] - #[doc = " @param[out] flags Address where the flags will be returned."] - #[doc = " @return A non-zero error value on failure and 0 on success."] + #[doc = "Retrieve the DB flags for a database handle.\n\nReturns:\n\n* A non-zero error value on failure and 0 on success.\n\n# Arguments\n\n* `txn` - A transaction handle returned by #mdb_txn_begin() [Direction: In]\n* `dbi` - A database handle returned by #mdb_dbi_open() [Direction: In]\n* `flags` - Address where the flags will be returned. [Direction: In, Out]\n\n"] pub fn mdb_dbi_flags( txn: *mut MDB_txn, dbi: MDB_dbi, @@ -1003,112 +387,27 @@ extern "C" { ) -> ::libc::c_int; } extern "C" { - #[doc = " @brief Close a database handle. Normally unnecessary. Use with care:"] - #[doc = ""] - #[doc = " This call is not mutex protected. Handles should only be closed by"] - #[doc = " a single thread, and only if no other threads are going to reference"] - #[doc = " the database handle or one of its cursors any further. Do not close"] - #[doc = " a handle if an existing transaction has modified its database."] - #[doc = " Doing so can cause misbehavior from database corruption to errors"] - #[doc = " like MDB_BAD_VALSIZE (since the DB name is gone)."] - #[doc = ""] - #[doc = " Closing a database handle is not necessary, but lets #mdb_dbi_open()"] - #[doc = " reuse the handle value. Usually it's better to set a bigger"] - #[doc = " #mdb_env_set_maxdbs(), unless that value would be large."] - #[doc = ""] - #[doc = " @param[in] env An environment handle returned by #mdb_env_create()"] - #[doc = " @param[in] dbi A database handle returned by #mdb_dbi_open()"] + #[doc = "Close a database handle. Normally unnecessary. Use with care:\n\nThis call is not mutex protected. Handles should only be closed by\na single thread, and only if no other threads are going to reference\nthe database handle or one of its cursors any further. Do not close\na handle if an existing transaction has modified its database.\nDoing so can cause misbehavior from database corruption to errors\nlike MDB_BAD_VALSIZE (since the DB name is gone).\nClosing a database handle is not necessary, but lets #mdb_dbi_open()\nreuse the handle value. Usually it's better to set a bigger\n#mdb_env_set_maxdbs(), unless that value would be large.\n\n# Arguments\n\n* `env` - An environment handle returned by #mdb_env_create() [Direction: In]\n* `dbi` - A database handle returned by #mdb_dbi_open() [Direction: In]\n\n"] pub fn mdb_dbi_close(env: *mut MDB_env, dbi: MDB_dbi); } extern "C" { - #[doc = " @brief Empty or delete+close a database."] - #[doc = ""] - #[doc = " See #mdb_dbi_close() for restrictions about closing the DB handle."] - #[doc = " @param[in] txn A transaction handle returned by #mdb_txn_begin()"] - #[doc = " @param[in] dbi A database handle returned by #mdb_dbi_open()"] - #[doc = " @param[in] del 0 to empty the DB, 1 to delete it from the"] - #[doc = " environment and close the DB handle."] - #[doc = " @return A non-zero error value on failure and 0 on success."] + #[doc = "Empty or delete+close a database.\n\nSee #mdb_dbi_close() for restrictions about closing the DB handle.\nenvironment and close the DB handle.\n\nReturns:\n\n* A non-zero error value on failure and 0 on success.\n\n# Arguments\n\n* `txn` - A transaction handle returned by #mdb_txn_begin() [Direction: In]\n* `dbi` - A database handle returned by #mdb_dbi_open() [Direction: In]\n* `del` - 0 to empty the DB, 1 to delete it from the [Direction: In]\n\n"] pub fn mdb_drop(txn: *mut MDB_txn, dbi: MDB_dbi, del: ::libc::c_int) -> ::libc::c_int; } extern "C" { - #[doc = " @brief Set a custom key comparison function for a database."] - #[doc = ""] - #[doc = " The comparison function is called whenever it is necessary to compare a"] - #[doc = " key specified by the application with a key currently stored in the database."] - #[doc = " If no comparison function is specified, and no special key flags were specified"] - #[doc = " with #mdb_dbi_open(), the keys are compared lexically, with shorter keys collating"] - #[doc = " before longer keys."] - #[doc = " @warning This function must be called before any data access functions are used,"] - #[doc = " otherwise data corruption may occur. The same comparison function must be used by every"] - #[doc = " program accessing the database, every time the database is used."] - #[doc = " @param[in] txn A transaction handle returned by #mdb_txn_begin()"] - #[doc = " @param[in] dbi A database handle returned by #mdb_dbi_open()"] - #[doc = " @param[in] cmp A #MDB_cmp_func function"] - #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] - #[doc = " errors are:"] - #[doc = "
    "] - #[doc = "\t
  • EINVAL - an invalid parameter was specified."] - #[doc = "
"] + #[doc = "Set a custom key comparison function for a database.\n\nThe comparison function is called whenever it is necessary to compare a\nkey specified by the application with a key currently stored in the database.\nIf no comparison function is specified, and no special key flags were specified\nwith #mdb_dbi_open(), the keys are compared lexically, with shorter keys collating\nbefore longer keys.\notherwise data corruption may occur. The same comparison function must be used by every\nprogram accessing the database, every time the database is used.\nerrors are:\n
    \n
  • EINVAL - an invalid parameter was specified.\n
\n\n**Warning!**\n\n* This function must be called before any data access functions are used,\n\nReturns:\n\n* A non-zero error value on failure and 0 on success. Some possible\n\n# Arguments\n\n* `txn` - A transaction handle returned by #mdb_txn_begin() [Direction: In]\n* `dbi` - A database handle returned by #mdb_dbi_open() [Direction: In]\n* `cmp` - A #MDB_cmp_func function [Direction: In]\n\n"] pub fn mdb_set_compare(txn: *mut MDB_txn, dbi: MDB_dbi, cmp: MDB_cmp_func) -> ::libc::c_int; } extern "C" { - #[doc = " @brief Set a custom data comparison function for a #MDB_DUPSORT database."] - #[doc = ""] - #[doc = " This comparison function is called whenever it is necessary to compare a data"] - #[doc = " item specified by the application with a data item currently stored in the database."] - #[doc = " This function only takes effect if the database was opened with the #MDB_DUPSORT"] - #[doc = " flag."] - #[doc = " If no comparison function is specified, and no special key flags were specified"] - #[doc = " with #mdb_dbi_open(), the data items are compared lexically, with shorter items collating"] - #[doc = " before longer items."] - #[doc = " @warning This function must be called before any data access functions are used,"] - #[doc = " otherwise data corruption may occur. The same comparison function must be used by every"] - #[doc = " program accessing the database, every time the database is used."] - #[doc = " @param[in] txn A transaction handle returned by #mdb_txn_begin()"] - #[doc = " @param[in] dbi A database handle returned by #mdb_dbi_open()"] - #[doc = " @param[in] cmp A #MDB_cmp_func function"] - #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] - #[doc = " errors are:"] - #[doc = "
    "] - #[doc = "\t
  • EINVAL - an invalid parameter was specified."] - #[doc = "
"] + #[doc = "Set a custom data comparison function for a #MDB_DUPSORT database.\n\nThis comparison function is called whenever it is necessary to compare a data\nitem specified by the application with a data item currently stored in the database.\nThis function only takes effect if the database was opened with the #MDB_DUPSORT\nflag.\nIf no comparison function is specified, and no special key flags were specified\nwith #mdb_dbi_open(), the data items are compared lexically, with shorter items collating\nbefore longer items.\notherwise data corruption may occur. The same comparison function must be used by every\nprogram accessing the database, every time the database is used.\nerrors are:\n
    \n
  • EINVAL - an invalid parameter was specified.\n
\n\n**Warning!**\n\n* This function must be called before any data access functions are used,\n\nReturns:\n\n* A non-zero error value on failure and 0 on success. Some possible\n\n# Arguments\n\n* `txn` - A transaction handle returned by #mdb_txn_begin() [Direction: In]\n* `dbi` - A database handle returned by #mdb_dbi_open() [Direction: In]\n* `cmp` - A #MDB_cmp_func function [Direction: In]\n\n"] pub fn mdb_set_dupsort(txn: *mut MDB_txn, dbi: MDB_dbi, cmp: MDB_cmp_func) -> ::libc::c_int; } extern "C" { - #[doc = " @brief Set a relocation function for a #MDB_FIXEDMAP database."] - #[doc = ""] - #[doc = " @todo The relocation function is called whenever it is necessary to move the data"] - #[doc = " of an item to a different position in the database (e.g. through tree"] - #[doc = " balancing operations, shifts as a result of adds or deletes, etc.). It is"] - #[doc = " intended to allow address/position-dependent data items to be stored in"] - #[doc = " a database in an environment opened with the #MDB_FIXEDMAP option."] - #[doc = " Currently the relocation feature is unimplemented and setting"] - #[doc = " this function has no effect."] - #[doc = " @param[in] txn A transaction handle returned by #mdb_txn_begin()"] - #[doc = " @param[in] dbi A database handle returned by #mdb_dbi_open()"] - #[doc = " @param[in] rel A #MDB_rel_func function"] - #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] - #[doc = " errors are:"] - #[doc = "
    "] - #[doc = "\t
  • EINVAL - an invalid parameter was specified."] - #[doc = "
"] + #[doc = "Set a relocation function for a #MDB_FIXEDMAP database.\n\nReturns:\n\n* A non-zero error value on failure and 0 on success. Some possible\n\n# Arguments\n\n* `txn` - A transaction handle returned by #mdb_txn_begin() [Direction: In]\n* `dbi` - A database handle returned by #mdb_dbi_open() [Direction: In]\n* `rel` - A #MDB_rel_func function [Direction: In]\n\n# To Do\n\n* The relocation function is called whenever it is necessary to move the data\nof an item to a different position in the database (e.g. through tree\nbalancing operations, shifts as a result of adds or deletes, etc.). It is\nintended to allow address/position-dependent data items to be stored in\na database in an environment opened with the #MDB_FIXEDMAP option.\nCurrently the relocation feature is unimplemented and setting\nthis function has no effect.\nerrors are:\n
    \n
  • EINVAL - an invalid parameter was specified.\n
\n"] pub fn mdb_set_relfunc(txn: *mut MDB_txn, dbi: MDB_dbi, rel: MDB_rel_func) -> ::libc::c_int; } extern "C" { - #[doc = " @brief Set a context pointer for a #MDB_FIXEDMAP database's relocation function."] - #[doc = ""] - #[doc = " See #mdb_set_relfunc and #MDB_rel_func for more details."] - #[doc = " @param[in] txn A transaction handle returned by #mdb_txn_begin()"] - #[doc = " @param[in] dbi A database handle returned by #mdb_dbi_open()"] - #[doc = " @param[in] ctx An arbitrary pointer for whatever the application needs."] - #[doc = " It will be passed to the callback function set by #mdb_set_relfunc"] - #[doc = " as its \\b relctx parameter whenever the callback is invoked."] - #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] - #[doc = " errors are:"] - #[doc = "
    "] - #[doc = "\t
  • EINVAL - an invalid parameter was specified."] - #[doc = "
"] + #[doc = "Set a context pointer for a #MDB_FIXEDMAP database's relocation function.\n\nSee #mdb_set_relfunc and #MDB_rel_func for more details.\nIt will be passed to the callback function set by #mdb_set_relfunc\nas its \\b relctx parameter whenever the callback is invoked.\nerrors are:\n
    \n
  • EINVAL - an invalid parameter was specified.\n
\n\nReturns:\n\n* A non-zero error value on failure and 0 on success. Some possible\n\n# Arguments\n\n* `txn` - A transaction handle returned by #mdb_txn_begin() [Direction: In]\n* `dbi` - A database handle returned by #mdb_dbi_open() [Direction: In]\n* `ctx` - An arbitrary pointer for whatever the application needs. [Direction: In]\n\n"] pub fn mdb_set_relctx( txn: *mut MDB_txn, dbi: MDB_dbi, @@ -1116,31 +415,7 @@ extern "C" { ) -> ::libc::c_int; } extern "C" { - #[doc = " @brief Get items from a database."] - #[doc = ""] - #[doc = " This function retrieves key/data pairs from the database. The address"] - #[doc = " and length of the data associated with the specified \\b key are returned"] - #[doc = " in the structure to which \\b data refers."] - #[doc = " If the database supports duplicate keys (#MDB_DUPSORT) then the"] - #[doc = " first data item for the key will be returned. Retrieval of other"] - #[doc = " items requires the use of #mdb_cursor_get()."] - #[doc = ""] - #[doc = " @note The memory pointed to by the returned values is owned by the"] - #[doc = " database. The caller need not dispose of the memory, and may not"] - #[doc = " modify it in any way. For values returned in a read-only transaction"] - #[doc = " any modification attempts will cause a SIGSEGV."] - #[doc = " @note Values returned from the database are valid only until a"] - #[doc = " subsequent update operation, or the end of the transaction."] - #[doc = " @param[in] txn A transaction handle returned by #mdb_txn_begin()"] - #[doc = " @param[in] dbi A database handle returned by #mdb_dbi_open()"] - #[doc = " @param[in] key The key to search for in the database"] - #[doc = " @param[out] data The data corresponding to the key"] - #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] - #[doc = " errors are:"] - #[doc = "
    "] - #[doc = "\t
  • #MDB_NOTFOUND - the key was not in the database."] - #[doc = "\t
  • EINVAL - an invalid parameter was specified."] - #[doc = "
"] + #[doc = "Get items from a database.\n\nThis function retrieves key/data pairs from the database. The address\nand length of the data associated with the specified \\b key are returned\nin the structure to which \\b data refers.\nIf the database supports duplicate keys (#MDB_DUPSORT) then the\nfirst data item for the key will be returned. Retrieval of other\nitems requires the use of #mdb_cursor_get().\ndatabase. The caller need not dispose of the memory, and may not\nmodify it in any way. For values returned in a read-only transaction\nany modification attempts will cause a SIGSEGV.\nsubsequent update operation, or the end of the transaction.\nerrors are:\n
    \n
  • #MDB_NOTFOUND - the key was not in the database.\n
  • EINVAL - an invalid parameter was specified.\n
\n\nReturns:\n\n* A non-zero error value on failure and 0 on success. Some possible\n\n# Arguments\n\n* `txn` - A transaction handle returned by #mdb_txn_begin() [Direction: In]\n* `dbi` - A database handle returned by #mdb_dbi_open() [Direction: In]\n* `key` - The key to search for in the database [Direction: In]\n* `data` - The data corresponding to the key [Direction: In, Out]\n\n# Notes\n\n* The memory pointed to by the returned values is owned by the\n* Values returned from the database are valid only until a\n\n"] pub fn mdb_get( txn: *mut MDB_txn, dbi: MDB_dbi, @@ -1149,52 +424,7 @@ extern "C" { ) -> ::libc::c_int; } extern "C" { - #[doc = " @brief Store items into a database."] - #[doc = ""] - #[doc = " This function stores key/data pairs in the database. The default behavior"] - #[doc = " is to enter the new key/data pair, replacing any previously existing key"] - #[doc = " if duplicates are disallowed, or adding a duplicate data item if"] - #[doc = " duplicates are allowed (#MDB_DUPSORT)."] - #[doc = " @param[in] txn A transaction handle returned by #mdb_txn_begin()"] - #[doc = " @param[in] dbi A database handle returned by #mdb_dbi_open()"] - #[doc = " @param[in] key The key to store in the database"] - #[doc = " @param[in,out] data The data to store"] - #[doc = " @param[in] flags Special options for this operation. This parameter"] - #[doc = " must be set to 0 or by bitwise OR'ing together one or more of the"] - #[doc = " values described here."] - #[doc = "
    "] - #[doc = "\t
  • #MDB_NODUPDATA - enter the new key/data pair only if it does not"] - #[doc = "\t\talready appear in the database. This flag may only be specified"] - #[doc = "\t\tif the database was opened with #MDB_DUPSORT. The function will"] - #[doc = "\t\treturn #MDB_KEYEXIST if the key/data pair already appears in the"] - #[doc = "\t\tdatabase."] - #[doc = "\t
  • #MDB_NOOVERWRITE - enter the new key/data pair only if the key"] - #[doc = "\t\tdoes not already appear in the database. The function will return"] - #[doc = "\t\t#MDB_KEYEXIST if the key already appears in the database, even if"] - #[doc = "\t\tthe database supports duplicates (#MDB_DUPSORT). The \\b data"] - #[doc = "\t\tparameter will be set to point to the existing item."] - #[doc = "\t
  • #MDB_RESERVE - reserve space for data of the given size, but"] - #[doc = "\t\tdon't copy the given data. Instead, return a pointer to the"] - #[doc = "\t\treserved space, which the caller can fill in later - before"] - #[doc = "\t\tthe next update operation or the transaction ends. This saves"] - #[doc = "\t\tan extra memcpy if the data is being generated later."] - #[doc = "\t\tLMDB does nothing else with this memory, the caller is expected"] - #[doc = "\t\tto modify all of the space requested. This flag must not be"] - #[doc = "\t\tspecified if the database was opened with #MDB_DUPSORT."] - #[doc = "\t
  • #MDB_APPEND - append the given key/data pair to the end of the"] - #[doc = "\t\tdatabase. This option allows fast bulk loading when keys are"] - #[doc = "\t\talready known to be in the correct order. Loading unsorted keys"] - #[doc = "\t\twith this flag will cause a #MDB_KEYEXIST error."] - #[doc = "\t
  • #MDB_APPENDDUP - as above, but for sorted dup data."] - #[doc = "
"] - #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] - #[doc = " errors are:"] - #[doc = "
    "] - #[doc = "\t
  • #MDB_MAP_FULL - the database is full, see #mdb_env_set_mapsize()."] - #[doc = "\t
  • #MDB_TXN_FULL - the transaction has too many dirty pages."] - #[doc = "\t
  • EACCES - an attempt was made to write in a read-only transaction."] - #[doc = "\t
  • EINVAL - an invalid parameter was specified."] - #[doc = "
"] + #[doc = "Store items into a database.\n\nThis function stores key/data pairs in the database. The default behavior\nis to enter the new key/data pair, replacing any previously existing key\nif duplicates are disallowed, or adding a duplicate data item if\nduplicates are allowed (#MDB_DUPSORT).\nmust be set to 0 or by bitwise OR'ing together one or more of the\nvalues described here.\n
    \n
  • #MDB_NODUPDATA - enter the new key/data pair only if it does not\nalready appear in the database. This flag may only be specified\nif the database was opened with #MDB_DUPSORT. The function will\nreturn #MDB_KEYEXIST if the key/data pair already appears in the\ndatabase.\n
  • #MDB_NOOVERWRITE - enter the new key/data pair only if the key\ndoes not already appear in the database. The function will return\n#MDB_KEYEXIST if the key already appears in the database, even if\nthe database supports duplicates (#MDB_DUPSORT). The \\b data\nparameter will be set to point to the existing item.\n
  • #MDB_RESERVE - reserve space for data of the given size, but\ndon't copy the given data. Instead, return a pointer to the\nreserved space, which the caller can fill in later - before\nthe next update operation or the transaction ends. This saves\nan extra memcpy if the data is being generated later.\nLMDB does nothing else with this memory, the caller is expected\nto modify all of the space requested. This flag must not be\nspecified if the database was opened with #MDB_DUPSORT.\n
  • #MDB_APPEND - append the given key/data pair to the end of the\ndatabase. This option allows fast bulk loading when keys are\nalready known to be in the correct order. Loading unsorted keys\nwith this flag will cause a #MDB_KEYEXIST error.\n
  • #MDB_APPENDDUP - as above, but for sorted dup data.\n
\nerrors are:\n
    \n
  • #MDB_MAP_FULL - the database is full, see #mdb_env_set_mapsize().\n
  • #MDB_TXN_FULL - the transaction has too many dirty pages.\n
  • EACCES - an attempt was made to write in a read-only transaction.\n
  • EINVAL - an invalid parameter was specified.\n
\n\nReturns:\n\n* A non-zero error value on failure and 0 on success. Some possible\n\n# Arguments\n\n* `txn` - A transaction handle returned by #mdb_txn_begin() [Direction: In]\n* `dbi` - A database handle returned by #mdb_dbi_open() [Direction: In]\n* `key` - The key to store in the database [Direction: In]\n* `data` - The data to store [Direction: Out]\n* `flags` - Special options for this operation. This parameter [Direction: In]\n\n"] pub fn mdb_put( txn: *mut MDB_txn, dbi: MDB_dbi, @@ -1204,27 +434,7 @@ extern "C" { ) -> ::libc::c_int; } extern "C" { - #[doc = " @brief Delete items from a database."] - #[doc = ""] - #[doc = " This function removes key/data pairs from the database."] - #[doc = " If the database does not support sorted duplicate data items"] - #[doc = " (#MDB_DUPSORT) the data parameter is ignored."] - #[doc = " If the database supports sorted duplicates and the data parameter"] - #[doc = " is NULL, all of the duplicate data items for the key will be"] - #[doc = " deleted. Otherwise, if the data parameter is non-NULL"] - #[doc = " only the matching data item will be deleted."] - #[doc = " This function will return #MDB_NOTFOUND if the specified key/data"] - #[doc = " pair is not in the database."] - #[doc = " @param[in] txn A transaction handle returned by #mdb_txn_begin()"] - #[doc = " @param[in] dbi A database handle returned by #mdb_dbi_open()"] - #[doc = " @param[in] key The key to delete from the database"] - #[doc = " @param[in] data The data to delete"] - #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] - #[doc = " errors are:"] - #[doc = "
    "] - #[doc = "\t
  • EACCES - an attempt was made to write in a read-only transaction."] - #[doc = "\t
  • EINVAL - an invalid parameter was specified."] - #[doc = "
"] + #[doc = "Delete items from a database.\n\nThis function removes key/data pairs from the database.\nIf the database does not support sorted duplicate data items\n(#MDB_DUPSORT) the data parameter is ignored.\nIf the database supports sorted duplicates and the data parameter\nis NULL, all of the duplicate data items for the key will be\ndeleted. Otherwise, if the data parameter is non-NULL\nonly the matching data item will be deleted.\nThis function will return #MDB_NOTFOUND if the specified key/data\npair is not in the database.\nerrors are:\n
    \n
  • EACCES - an attempt was made to write in a read-only transaction.\n
  • EINVAL - an invalid parameter was specified.\n
\n\nReturns:\n\n* A non-zero error value on failure and 0 on success. Some possible\n\n# Arguments\n\n* `txn` - A transaction handle returned by #mdb_txn_begin() [Direction: In]\n* `dbi` - A database handle returned by #mdb_dbi_open() [Direction: In]\n* `key` - The key to delete from the database [Direction: In]\n* `data` - The data to delete [Direction: In]\n\n"] pub fn mdb_del( txn: *mut MDB_txn, dbi: MDB_dbi, @@ -1233,27 +443,7 @@ extern "C" { ) -> ::libc::c_int; } extern "C" { - #[doc = " @brief Create a cursor handle."] - #[doc = ""] - #[doc = " A cursor is associated with a specific transaction and database."] - #[doc = " A cursor cannot be used when its database handle is closed. Nor"] - #[doc = " when its transaction has ended, except with #mdb_cursor_renew()."] - #[doc = " It can be discarded with #mdb_cursor_close()."] - #[doc = " A cursor in a write-transaction can be closed before its transaction"] - #[doc = " ends, and will otherwise be closed when its transaction ends."] - #[doc = " A cursor in a read-only transaction must be closed explicitly, before"] - #[doc = " or after its transaction ends. It can be reused with"] - #[doc = " #mdb_cursor_renew() before finally closing it."] - #[doc = " @note Earlier documentation said that cursors in every transaction"] - #[doc = " were closed when the transaction committed or aborted."] - #[doc = " @param[in] txn A transaction handle returned by #mdb_txn_begin()"] - #[doc = " @param[in] dbi A database handle returned by #mdb_dbi_open()"] - #[doc = " @param[out] cursor Address where the new #MDB_cursor handle will be stored"] - #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] - #[doc = " errors are:"] - #[doc = "
    "] - #[doc = "\t
  • EINVAL - an invalid parameter was specified."] - #[doc = "
"] + #[doc = "Create a cursor handle.\n\nA cursor is associated with a specific transaction and database.\nA cursor cannot be used when its database handle is closed. Nor\nwhen its transaction has ended, except with #mdb_cursor_renew().\nIt can be discarded with #mdb_cursor_close().\nA cursor in a write-transaction can be closed before its transaction\nends, and will otherwise be closed when its transaction ends.\nA cursor in a read-only transaction must be closed explicitly, before\nor after its transaction ends. It can be reused with\n#mdb_cursor_renew() before finally closing it.\nwere closed when the transaction committed or aborted.\nerrors are:\n
    \n
  • EINVAL - an invalid parameter was specified.\n
\n\nReturns:\n\n* A non-zero error value on failure and 0 on success. Some possible\n\n# Arguments\n\n* `txn` - A transaction handle returned by #mdb_txn_begin() [Direction: In]\n* `dbi` - A database handle returned by #mdb_dbi_open() [Direction: In]\n* `cursor` - Address where the new #MDB_cursor handle will be stored [Direction: In, Out]\n\n# Notes\n\n* Earlier documentation said that cursors in every transaction\n\n"] pub fn mdb_cursor_open( txn: *mut MDB_txn, dbi: MDB_dbi, @@ -1261,69 +451,27 @@ extern "C" { ) -> ::libc::c_int; } extern "C" { - #[doc = " @brief Close a cursor handle."] - #[doc = ""] - #[doc = " The cursor handle will be freed and must not be used again after this call."] - #[doc = " Its transaction must still be live if it is a write-transaction."] - #[doc = " @param[in] cursor A cursor handle returned by #mdb_cursor_open()"] + #[doc = "Close a cursor handle.\n\nThe cursor handle will be freed and must not be used again after this call.\nIts transaction must still be live if it is a write-transaction.\n\n# Arguments\n\n* `cursor` - A cursor handle returned by #mdb_cursor_open() [Direction: In]\n\n"] pub fn mdb_cursor_close(cursor: *mut MDB_cursor); } extern "C" { - #[doc = " @brief Renew a cursor handle."] - #[doc = ""] - #[doc = " A cursor is associated with a specific transaction and database."] - #[doc = " Cursors that are only used in read-only"] - #[doc = " transactions may be re-used, to avoid unnecessary malloc/free overhead."] - #[doc = " The cursor may be associated with a new read-only transaction, and"] - #[doc = " referencing the same database handle as it was created with."] - #[doc = " This may be done whether the previous transaction is live or dead."] - #[doc = " @param[in] txn A transaction handle returned by #mdb_txn_begin()"] - #[doc = " @param[in] cursor A cursor handle returned by #mdb_cursor_open()"] - #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] - #[doc = " errors are:"] - #[doc = "
    "] - #[doc = "\t
  • EINVAL - an invalid parameter was specified."] - #[doc = "
"] + #[doc = "Renew a cursor handle.\n\nA cursor is associated with a specific transaction and database.\nCursors that are only used in read-only\ntransactions may be re-used, to avoid unnecessary malloc/free overhead.\nThe cursor may be associated with a new read-only transaction, and\nreferencing the same database handle as it was created with.\nThis may be done whether the previous transaction is live or dead.\nerrors are:\n
    \n
  • EINVAL - an invalid parameter was specified.\n
\n\nReturns:\n\n* A non-zero error value on failure and 0 on success. Some possible\n\n# Arguments\n\n* `txn` - A transaction handle returned by #mdb_txn_begin() [Direction: In]\n* `cursor` - A cursor handle returned by #mdb_cursor_open() [Direction: In]\n\n"] pub fn mdb_cursor_renew(txn: *mut MDB_txn, cursor: *mut MDB_cursor) -> ::libc::c_int; } extern "C" { - #[doc = " @brief Return the cursor's transaction handle."] - #[doc = ""] - #[doc = " @param[in] cursor A cursor handle returned by #mdb_cursor_open()"] + #[doc = "Return the cursor's transaction handle.\n\n# Arguments\n\n* `cursor` - A cursor handle returned by #mdb_cursor_open() [Direction: In]\n\n"] pub fn mdb_cursor_txn(cursor: *mut MDB_cursor) -> *mut MDB_txn; } extern "C" { - #[doc = " @brief Return the cursor's database handle."] - #[doc = ""] - #[doc = " @param[in] cursor A cursor handle returned by #mdb_cursor_open()"] + #[doc = "Return the cursor's database handle.\n\n# Arguments\n\n* `cursor` - A cursor handle returned by #mdb_cursor_open() [Direction: In]\n\n"] pub fn mdb_cursor_dbi(cursor: *mut MDB_cursor) -> MDB_dbi; } extern "C" { - #[doc = " @brief Check if the cursor is pointing to a named database record."] - #[doc = ""] - #[doc = " @param[in] cursor A cursor handle returned by #mdb_cursor_open()"] - #[doc = " @return 1 if current record is a named database, 0 otherwise."] + #[doc = "Check if the cursor is pointing to a named database record.\n\nReturns:\n\n* 1 if current record is a named database, 0 otherwise.\n\n# Arguments\n\n* `cursor` - A cursor handle returned by #mdb_cursor_open() [Direction: In]\n\n"] pub fn mdb_cursor_is_db(cursor: *mut MDB_cursor) -> ::libc::c_int; } extern "C" { - #[doc = " @brief Retrieve by cursor."] - #[doc = ""] - #[doc = " This function retrieves key/data pairs from the database. The address and length"] - #[doc = " of the key are returned in the object to which \\b key refers (except for the"] - #[doc = " case of the #MDB_SET option, in which the \\b key object is unchanged), and"] - #[doc = " the address and length of the data are returned in the object to which \\b data"] - #[doc = " refers."] - #[doc = " See #mdb_get() for restrictions on using the output values."] - #[doc = " @param[in] cursor A cursor handle returned by #mdb_cursor_open()"] - #[doc = " @param[in,out] key The key for a retrieved item"] - #[doc = " @param[in,out] data The data of a retrieved item"] - #[doc = " @param[in] op A cursor operation #MDB_cursor_op"] - #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] - #[doc = " errors are:"] - #[doc = "
    "] - #[doc = "\t
  • #MDB_NOTFOUND - no matching key found."] - #[doc = "\t
  • EINVAL - an invalid parameter was specified."] - #[doc = "
"] + #[doc = "Retrieve by cursor.\n\nThis function retrieves key/data pairs from the database. The address and length\nof the key are returned in the object to which \\b key refers (except for the\ncase of the #MDB_SET option, in which the \\b key object is unchanged), and\nthe address and length of the data are returned in the object to which \\b data\nrefers.\nSee #mdb_get() for restrictions on using the output values.\nerrors are:\n
    \n
  • #MDB_NOTFOUND - no matching key found.\n
  • EINVAL - an invalid parameter was specified.\n
\n\nReturns:\n\n* A non-zero error value on failure and 0 on success. Some possible\n\n# Arguments\n\n* `cursor` - A cursor handle returned by #mdb_cursor_open() [Direction: In]\n* `key` - The key for a retrieved item [Direction: Out]\n* `data` - The data of a retrieved item [Direction: Out]\n* `op` - A cursor operation #MDB_cursor_op [Direction: In]\n\n"] pub fn mdb_cursor_get( cursor: *mut MDB_cursor, key: *mut MDB_val, @@ -1332,64 +480,7 @@ extern "C" { ) -> ::libc::c_int; } extern "C" { - #[doc = " @brief Store by cursor."] - #[doc = ""] - #[doc = " This function stores key/data pairs into the database."] - #[doc = " The cursor is positioned at the new item, or on failure usually near it."] - #[doc = " @note Earlier documentation incorrectly said errors would leave the"] - #[doc = " state of the cursor unchanged."] - #[doc = " @param[in] cursor A cursor handle returned by #mdb_cursor_open()"] - #[doc = " @param[in] key The key operated on."] - #[doc = " @param[in] data The data operated on."] - #[doc = " @param[in] flags Options for this operation. This parameter"] - #[doc = " must be set to 0 or one of the values described here."] - #[doc = "
    "] - #[doc = "\t
  • #MDB_CURRENT - replace the item at the current cursor position."] - #[doc = "\t\tThe \\b key parameter must still be provided, and must match it."] - #[doc = "\t\tIf using sorted duplicates (#MDB_DUPSORT) the data item must still"] - #[doc = "\t\tsort into the same place. This is intended to be used when the"] - #[doc = "\t\tnew data is the same size as the old. Otherwise it will simply"] - #[doc = "\t\tperform a delete of the old record followed by an insert."] - #[doc = "\t
  • #MDB_NODUPDATA - enter the new key/data pair only if it does not"] - #[doc = "\t\talready appear in the database. This flag may only be specified"] - #[doc = "\t\tif the database was opened with #MDB_DUPSORT. The function will"] - #[doc = "\t\treturn #MDB_KEYEXIST if the key/data pair already appears in the"] - #[doc = "\t\tdatabase."] - #[doc = "\t
  • #MDB_NOOVERWRITE - enter the new key/data pair only if the key"] - #[doc = "\t\tdoes not already appear in the database. The function will return"] - #[doc = "\t\t#MDB_KEYEXIST if the key already appears in the database, even if"] - #[doc = "\t\tthe database supports duplicates (#MDB_DUPSORT)."] - #[doc = "\t
  • #MDB_RESERVE - reserve space for data of the given size, but"] - #[doc = "\t\tdon't copy the given data. Instead, return a pointer to the"] - #[doc = "\t\treserved space, which the caller can fill in later - before"] - #[doc = "\t\tthe next update operation or the transaction ends. This saves"] - #[doc = "\t\tan extra memcpy if the data is being generated later. This flag"] - #[doc = "\t\tmust not be specified if the database was opened with #MDB_DUPSORT."] - #[doc = "\t
  • #MDB_APPEND - append the given key/data pair to the end of the"] - #[doc = "\t\tdatabase. No key comparisons are performed. This option allows"] - #[doc = "\t\tfast bulk loading when keys are already known to be in the"] - #[doc = "\t\tcorrect order. Loading unsorted keys with this flag will cause"] - #[doc = "\t\ta #MDB_KEYEXIST error."] - #[doc = "\t
  • #MDB_APPENDDUP - as above, but for sorted dup data."] - #[doc = "\t
  • #MDB_MULTIPLE - store multiple contiguous data elements in a"] - #[doc = "\t\tsingle request. This flag may only be specified if the database"] - #[doc = "\t\twas opened with #MDB_DUPFIXED. The \\b data argument must be an"] - #[doc = "\t\tarray of two MDB_vals. The mv_size of the first MDB_val must be"] - #[doc = "\t\tthe size of a single data element. The mv_data of the first MDB_val"] - #[doc = "\t\tmust point to the beginning of the array of contiguous data elements."] - #[doc = "\t\tThe mv_size of the second MDB_val must be the count of the number"] - #[doc = "\t\tof data elements to store. On return this field will be set to"] - #[doc = "\t\tthe count of the number of elements actually written. The mv_data"] - #[doc = "\t\tof the second MDB_val is unused."] - #[doc = "
"] - #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] - #[doc = " errors are:"] - #[doc = "
    "] - #[doc = "\t
  • #MDB_MAP_FULL - the database is full, see #mdb_env_set_mapsize()."] - #[doc = "\t
  • #MDB_TXN_FULL - the transaction has too many dirty pages."] - #[doc = "\t
  • EACCES - an attempt was made to write in a read-only transaction."] - #[doc = "\t
  • EINVAL - an invalid parameter was specified."] - #[doc = "
"] + #[doc = "Store by cursor.\n\nThis function stores key/data pairs into the database.\nThe cursor is positioned at the new item, or on failure usually near it.\nstate of the cursor unchanged.\nmust be set to 0 or one of the values described here.\n
    \n
  • #MDB_CURRENT - replace the item at the current cursor position.\nThe \\b key parameter must still be provided, and must match it.\nIf using sorted duplicates (#MDB_DUPSORT) the data item must still\nsort into the same place. This is intended to be used when the\nnew data is the same size as the old. Otherwise it will simply\nperform a delete of the old record followed by an insert.\n
  • #MDB_NODUPDATA - enter the new key/data pair only if it does not\nalready appear in the database. This flag may only be specified\nif the database was opened with #MDB_DUPSORT. The function will\nreturn #MDB_KEYEXIST if the key/data pair already appears in the\ndatabase.\n
  • #MDB_NOOVERWRITE - enter the new key/data pair only if the key\ndoes not already appear in the database. The function will return\n#MDB_KEYEXIST if the key already appears in the database, even if\nthe database supports duplicates (#MDB_DUPSORT).\n
  • #MDB_RESERVE - reserve space for data of the given size, but\ndon't copy the given data. Instead, return a pointer to the\nreserved space, which the caller can fill in later - before\nthe next update operation or the transaction ends. This saves\nan extra memcpy if the data is being generated later. This flag\nmust not be specified if the database was opened with #MDB_DUPSORT.\n
  • #MDB_APPEND - append the given key/data pair to the end of the\ndatabase. No key comparisons are performed. This option allows\nfast bulk loading when keys are already known to be in the\ncorrect order. Loading unsorted keys with this flag will cause\na #MDB_KEYEXIST error.\n
  • #MDB_APPENDDUP - as above, but for sorted dup data.\n
  • #MDB_MULTIPLE - store multiple contiguous data elements in a\nsingle request. This flag may only be specified if the database\nwas opened with #MDB_DUPFIXED. The \\b data argument must be an\narray of two MDB_vals. The mv_size of the first MDB_val must be\nthe size of a single data element. The mv_data of the first MDB_val\nmust point to the beginning of the array of contiguous data elements.\nThe mv_size of the second MDB_val must be the count of the number\nof data elements to store. On return this field will be set to\nthe count of the number of elements actually written. The mv_data\nof the second MDB_val is unused.\n
\nerrors are:\n
    \n
  • #MDB_MAP_FULL - the database is full, see #mdb_env_set_mapsize().\n
  • #MDB_TXN_FULL - the transaction has too many dirty pages.\n
  • EACCES - an attempt was made to write in a read-only transaction.\n
  • EINVAL - an invalid parameter was specified.\n
\n\nReturns:\n\n* A non-zero error value on failure and 0 on success. Some possible\n\n# Arguments\n\n* `cursor` - A cursor handle returned by #mdb_cursor_open() [Direction: In]\n* `key` - The key operated on. [Direction: In]\n* `data` - The data operated on. [Direction: In]\n* `flags` - Options for this operation. This parameter [Direction: In]\n\n# Notes\n\n* Earlier documentation incorrectly said errors would leave the\n\n"] pub fn mdb_cursor_put( cursor: *mut MDB_cursor, key: *mut MDB_val, @@ -1398,52 +489,15 @@ extern "C" { ) -> ::libc::c_int; } extern "C" { - #[doc = " @brief Delete current key/data pair"] - #[doc = ""] - #[doc = " This function deletes the key/data pair to which the cursor refers."] - #[doc = " This does not invalidate the cursor, so operations such as MDB_NEXT"] - #[doc = " can still be used on it."] - #[doc = " Both MDB_NEXT and MDB_GET_CURRENT will return the same record after"] - #[doc = " this operation."] - #[doc = " @param[in] cursor A cursor handle returned by #mdb_cursor_open()"] - #[doc = " @param[in] flags Options for this operation. This parameter"] - #[doc = " must be set to 0 or one of the values described here."] - #[doc = "
    "] - #[doc = "\t
  • #MDB_NODUPDATA - delete all of the data items for the current key."] - #[doc = "\t\tThis flag may only be specified if the database was opened with #MDB_DUPSORT."] - #[doc = "
"] - #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] - #[doc = " errors are:"] - #[doc = "
    "] - #[doc = "\t
  • EACCES - an attempt was made to write in a read-only transaction."] - #[doc = "\t
  • EINVAL - an invalid parameter was specified."] - #[doc = "
"] + #[doc = "Delete current key/data pair\n\nThis function deletes the key/data pair to which the cursor refers.\nThis does not invalidate the cursor, so operations such as MDB_NEXT\ncan still be used on it.\nBoth MDB_NEXT and MDB_GET_CURRENT will return the same record after\nthis operation.\nmust be set to 0 or one of the values described here.\n
    \n
  • #MDB_NODUPDATA - delete all of the data items for the current key.\nThis flag may only be specified if the database was opened with #MDB_DUPSORT.\n
\nerrors are:\n
    \n
  • EACCES - an attempt was made to write in a read-only transaction.\n
  • EINVAL - an invalid parameter was specified.\n
\n\nReturns:\n\n* A non-zero error value on failure and 0 on success. Some possible\n\n# Arguments\n\n* `cursor` - A cursor handle returned by #mdb_cursor_open() [Direction: In]\n* `flags` - Options for this operation. This parameter [Direction: In]\n\n"] pub fn mdb_cursor_del(cursor: *mut MDB_cursor, flags: ::libc::c_uint) -> ::libc::c_int; } extern "C" { - #[doc = " @brief Return count of duplicates for current key."] - #[doc = ""] - #[doc = " This call is only valid on databases that support sorted duplicate"] - #[doc = " data items #MDB_DUPSORT."] - #[doc = " @param[in] cursor A cursor handle returned by #mdb_cursor_open()"] - #[doc = " @param[out] countp Address where the count will be stored"] - #[doc = " @return A non-zero error value on failure and 0 on success. Some possible"] - #[doc = " errors are:"] - #[doc = "
    "] - #[doc = "\t
  • EINVAL - cursor is not initialized, or an invalid parameter was specified."] - #[doc = "
"] + #[doc = "Return count of duplicates for current key.\n\nThis call is only valid on databases that support sorted duplicate\ndata items #MDB_DUPSORT.\nerrors are:\n
    \n
  • EINVAL - cursor is not initialized, or an invalid parameter was specified.\n
\n\nReturns:\n\n* A non-zero error value on failure and 0 on success. Some possible\n\n# Arguments\n\n* `cursor` - A cursor handle returned by #mdb_cursor_open() [Direction: In]\n* `countp` - Address where the count will be stored [Direction: In, Out]\n\n"] pub fn mdb_cursor_count(cursor: *mut MDB_cursor, countp: *mut mdb_size_t) -> ::libc::c_int; } extern "C" { - #[doc = " @brief Compare two data items according to a particular database."] - #[doc = ""] - #[doc = " This returns a comparison as if the two data items were keys in the"] - #[doc = " specified database."] - #[doc = " @param[in] txn A transaction handle returned by #mdb_txn_begin()"] - #[doc = " @param[in] dbi A database handle returned by #mdb_dbi_open()"] - #[doc = " @param[in] a The first item to compare"] - #[doc = " @param[in] b The second item to compare"] - #[doc = " @return < 0 if a < b, 0 if a == b, > 0 if a > b"] + #[doc = "Compare two data items according to a particular database.\n\nThis returns a comparison as if the two data items were keys in the\nspecified database.\n\nReturns:\n\n* < 0 if a < b, 0 if a == b, > 0 if a > b\n\n# Arguments\n\n* `txn` - A transaction handle returned by #mdb_txn_begin() [Direction: In]\n* `dbi` - A database handle returned by #mdb_dbi_open() [Direction: In]\n* `a` - The first item to compare [Direction: In]\n* `b` - The second item to compare [Direction: In]\n\n"] pub fn mdb_cmp( txn: *mut MDB_txn, dbi: MDB_dbi, @@ -1452,15 +506,7 @@ extern "C" { ) -> ::libc::c_int; } extern "C" { - #[doc = " @brief Compare two data items according to a particular database."] - #[doc = ""] - #[doc = " This returns a comparison as if the two items were data items of"] - #[doc = " the specified database. The database must have the #MDB_DUPSORT flag."] - #[doc = " @param[in] txn A transaction handle returned by #mdb_txn_begin()"] - #[doc = " @param[in] dbi A database handle returned by #mdb_dbi_open()"] - #[doc = " @param[in] a The first item to compare"] - #[doc = " @param[in] b The second item to compare"] - #[doc = " @return < 0 if a < b, 0 if a == b, > 0 if a > b"] + #[doc = "Compare two data items according to a particular database.\n\nThis returns a comparison as if the two items were data items of\nthe specified database. The database must have the #MDB_DUPSORT flag.\n\nReturns:\n\n* < 0 if a < b, 0 if a == b, > 0 if a > b\n\n# Arguments\n\n* `txn` - A transaction handle returned by #mdb_txn_begin() [Direction: In]\n* `dbi` - A database handle returned by #mdb_dbi_open() [Direction: In]\n* `a` - The first item to compare [Direction: In]\n* `b` - The second item to compare [Direction: In]\n\n"] pub fn mdb_dcmp( txn: *mut MDB_txn, dbi: MDB_dbi, @@ -1468,21 +514,12 @@ extern "C" { b: *const MDB_val, ) -> ::libc::c_int; } -#[doc = " @brief A callback function used to print a message from the library."] -#[doc = ""] -#[doc = " @param[in] msg The string to be printed."] -#[doc = " @param[in] ctx An arbitrary context pointer for the callback."] -#[doc = " @return < 0 on failure, >= 0 on success."] +#[doc = "A callback function used to print a message from the library.\n\nReturns:\n\n* < 0 on failure, >= 0 on success.\n\n# Arguments\n\n* `msg` - The string to be printed. [Direction: In]\n* `ctx` - An arbitrary context pointer for the callback. [Direction: In]\n\n"] pub type MDB_msg_func = ::std::option::Option< unsafe extern "C" fn(msg: *const ::libc::c_char, ctx: *mut ::libc::c_void) -> ::libc::c_int, >; extern "C" { - #[doc = " @brief Dump the entries in the reader lock table."] - #[doc = ""] - #[doc = " @param[in] env An environment handle returned by #mdb_env_create()"] - #[doc = " @param[in] func A #MDB_msg_func function"] - #[doc = " @param[in] ctx Anything the message function needs"] - #[doc = " @return < 0 on failure, >= 0 on success."] + #[doc = "Dump the entries in the reader lock table.\n\nReturns:\n\n* < 0 on failure, >= 0 on success.\n\n# Arguments\n\n* `env` - An environment handle returned by #mdb_env_create() [Direction: In]\n* `func` - A #MDB_msg_func function [Direction: In]\n* `ctx` - Anything the message function needs [Direction: In]\n\n"] pub fn mdb_reader_list( env: *mut MDB_env, func: MDB_msg_func, @@ -1490,42 +527,26 @@ extern "C" { ) -> ::libc::c_int; } extern "C" { - #[doc = " @brief Check for stale entries in the reader lock table."] - #[doc = ""] - #[doc = " @param[in] env An environment handle returned by #mdb_env_create()"] - #[doc = " @param[out] dead Number of stale slots that were cleared"] - #[doc = " @return 0 on success, non-zero on failure."] + #[doc = "Check for stale entries in the reader lock table.\n\nReturns:\n\n* 0 on success, non-zero on failure.\n\n# Arguments\n\n* `env` - An environment handle returned by #mdb_env_create() [Direction: In]\n* `dead` - Number of stale slots that were cleared [Direction: In, Out]\n\n"] pub fn mdb_reader_check(env: *mut MDB_env, dead: *mut ::libc::c_int) -> ::libc::c_int; } -#[doc = " @brief A function for converting a string into an encryption key."] -#[doc = ""] -#[doc = " @param[in] passwd The string to be converted."] -#[doc = " @param[in,out] key The resulting key. The caller must"] -#[doc = " provide the space for the key."] -#[doc = " @return 0 on success, non-zero on failure."] +#[doc = "A function for converting a string into an encryption key.\n\nprovide the space for the key.\n\nReturns:\n\n* 0 on success, non-zero on failure.\n\n# Arguments\n\n* `passwd` - The string to be converted. [Direction: In]\n* `key` - The resulting key. The caller must [Direction: Out]\n\n"] pub type MDB_str2key_func = ::std::option::Option< unsafe extern "C" fn(passwd: *const ::libc::c_char, key: *mut MDB_val) -> ::libc::c_int, >; -#[doc = " @brief A structure for dynamically loaded crypto modules."] -#[doc = ""] -#[doc = " This is the information that the command line tools expect"] -#[doc = " in order to operate on encrypted or checksummed environments."] +#[doc = "A structure for dynamically loaded crypto modules.\n\nThis is the information that the command line tools expect\nin order to operate on encrypted or checksummed environments.\n\n"] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct MDB_crypto_funcs { pub mcf_str2key: MDB_str2key_func, pub mcf_encfunc: MDB_enc_func, pub mcf_sumfunc: MDB_sum_func, - #[doc = "< The size of an encryption key, in bytes"] + #[doc = "The size of an encryption key, in bytes\n\n"] pub mcf_keysize: ::libc::c_int, - #[doc = "< The size of the MAC, for authenticated encryption"] + #[doc = "The size of the MAC, for authenticated encryption\n\n"] pub mcf_esumsize: ::libc::c_int, - #[doc = "< The size of the checksum, for plain checksums"] + #[doc = "The size of the checksum, for plain checksums\n\n"] pub mcf_sumsize: ::libc::c_int, } -#[doc = " @brief The function that returns the #MDB_crypto_funcs structure."] -#[doc = ""] -#[doc = " The command line tools expect this function to be named \"MDB_crypto\"."] -#[doc = " It must be exported by the dynamic module so that the tools can use it."] -#[doc = " @return A pointer to a #MDB_crypto_funcs structure."] +#[doc = "The function that returns the #MDB_crypto_funcs structure.\n\nThe command line tools expect this function to be named \"MDB_crypto\".\nIt must be exported by the dynamic module so that the tools can use it.\n\nReturns:\n\n* A pointer to a #MDB_crypto_funcs structure.\n\n"] pub type MDB_crypto_hooks = ::std::option::Option *mut MDB_crypto_funcs>; From eb2f85e02ef9dc0b20c9ffd8bd1b1f8a4d4414c9 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Sat, 24 Dec 2022 15:06:51 +0100 Subject: [PATCH 48/57] Rewrite the build.rs to be more Rust idiomatic wrt features --- lmdb-master3-sys/build.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lmdb-master3-sys/build.rs b/lmdb-master3-sys/build.rs index bb574e3f..150faee6 100644 --- a/lmdb-master3-sys/build.rs +++ b/lmdb-master3-sys/build.rs @@ -42,13 +42,13 @@ fn main() { .flag_if_supported("-Wbad-function-cast") .flag_if_supported("-Wuninitialized"); - if env::var("CARGO_FEATURE_WITH_ASAN").is_ok() { + if cfg!(feature = "with-asan") { builder.flag("-fsanitize=address"); } - if env::var("CARGO_FEATURE_WITH_FUZZER").is_ok() { + if cfg!(feature = "with-fuzzer") { builder.flag("-fsanitize=fuzzer"); - } else if env::var("CARGO_FEATURE_WITH_FUZZER_NO_LINK").is_ok() { + } else if cfg!(feature = "with-fuzzer-no-link") { builder.flag("-fsanitize=fuzzer-no-link"); } From a1ed4b14b1b035244be235bdca0015ffc7d7d7dc Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Sat, 24 Dec 2022 16:41:13 +0100 Subject: [PATCH 49/57] Check the validity of the env and transaction when opening databases --- heed/src/db/polymorph.rs | 54 ++++++++++++++++++++-------------------- heed/src/env.rs | 14 +++++++++-- heed/src/lib.rs | 13 ++++++++-- 3 files changed, 50 insertions(+), 31 deletions(-) diff --git a/heed/src/db/polymorph.rs b/heed/src/db/polymorph.rs index 5bb73c77..cc918bc8 100644 --- a/heed/src/db/polymorph.rs +++ b/heed/src/db/polymorph.rs @@ -158,7 +158,7 @@ impl PolyDatabase { KC: BytesEncode<'a>, DC: BytesDecode<'txn>, { - assert_matching_env_txn!(self, txn); + assert_eq_env_db_txn!(self, txn); let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).map_err(Error::Encoding)?; @@ -232,7 +232,7 @@ impl PolyDatabase { KC: BytesEncode<'a> + BytesDecode<'txn>, DC: BytesDecode<'txn>, { - assert_matching_env_txn!(self, txn); + assert_eq_env_db_txn!(self, txn); let mut cursor = RoCursor::new(txn, self.dbi)?; let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).map_err(Error::Encoding)?; @@ -300,7 +300,7 @@ impl PolyDatabase { KC: BytesEncode<'a> + BytesDecode<'txn>, DC: BytesDecode<'txn>, { - assert_matching_env_txn!(self, txn); + assert_eq_env_db_txn!(self, txn); let mut cursor = RoCursor::new(txn, self.dbi)?; let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).map_err(Error::Encoding)?; @@ -372,7 +372,7 @@ impl PolyDatabase { KC: BytesEncode<'a> + BytesDecode<'txn>, DC: BytesDecode<'txn>, { - assert_matching_env_txn!(self, txn); + assert_eq_env_db_txn!(self, txn); let mut cursor = RoCursor::new(txn, self.dbi)?; let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).map_err(Error::Encoding)?; @@ -443,7 +443,7 @@ impl PolyDatabase { KC: BytesEncode<'a> + BytesDecode<'txn>, DC: BytesDecode<'txn>, { - assert_matching_env_txn!(self, txn); + assert_eq_env_db_txn!(self, txn); let mut cursor = RoCursor::new(txn, self.dbi)?; let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).map_err(Error::Encoding)?; @@ -497,7 +497,7 @@ impl PolyDatabase { KC: BytesDecode<'txn>, DC: BytesDecode<'txn>, { - assert_matching_env_txn!(self, txn); + assert_eq_env_db_txn!(self, txn); let mut cursor = RoCursor::new(txn, self.dbi)?; match cursor.move_on_first() { @@ -550,7 +550,7 @@ impl PolyDatabase { KC: BytesDecode<'txn>, DC: BytesDecode<'txn>, { - assert_matching_env_txn!(self, txn); + assert_eq_env_db_txn!(self, txn); let mut cursor = RoCursor::new(txn, self.dbi)?; match cursor.move_on_last() { @@ -603,7 +603,7 @@ impl PolyDatabase { /// # Ok(()) } /// ``` pub fn len<'txn>(&self, txn: &'txn RoTxn) -> Result { - assert_matching_env_txn!(self, txn); + assert_eq_env_db_txn!(self, txn); let mut db_stat = mem::MaybeUninit::uninit(); let result = unsafe { mdb_result(ffi::mdb_stat(txn.txn, self.dbi, db_stat.as_mut_ptr())) }; @@ -656,7 +656,7 @@ impl PolyDatabase { /// # Ok(()) } /// ``` pub fn is_empty<'txn>(&self, txn: &'txn RoTxn) -> Result { - assert_matching_env_txn!(self, txn); + assert_eq_env_db_txn!(self, txn); let mut cursor = RoCursor::new(txn, self.dbi)?; match cursor.move_on_first()? { @@ -702,7 +702,7 @@ impl PolyDatabase { /// # Ok(()) } /// ``` pub fn iter<'txn, KC, DC>(&self, txn: &'txn RoTxn) -> Result> { - assert_matching_env_txn!(self, txn); + assert_eq_env_db_txn!(self, txn); RoCursor::new(txn, self.dbi).map(|cursor| RoIter::new(cursor)) } @@ -757,7 +757,7 @@ impl PolyDatabase { /// # Ok(()) } /// ``` pub fn iter_mut<'txn, KC, DC>(&self, txn: &'txn mut RwTxn) -> Result> { - assert_matching_env_txn!(self, txn); + assert_eq_env_db_txn!(self, txn); RwCursor::new(txn, self.dbi).map(|cursor| RwIter::new(cursor)) } @@ -799,7 +799,7 @@ impl PolyDatabase { /// # Ok(()) } /// ``` pub fn rev_iter<'txn, KC, DC>(&self, txn: &'txn RoTxn) -> Result> { - assert_matching_env_txn!(self, txn); + assert_eq_env_db_txn!(self, txn); RoCursor::new(txn, self.dbi).map(|cursor| RoRevIter::new(cursor)) } @@ -858,7 +858,7 @@ impl PolyDatabase { &self, txn: &'txn mut RwTxn, ) -> Result> { - assert_matching_env_txn!(self, txn); + assert_eq_env_db_txn!(self, txn); RwCursor::new(txn, self.dbi).map(|cursor| RwRevIter::new(cursor)) } @@ -911,7 +911,7 @@ impl PolyDatabase { KC: BytesEncode<'a>, R: RangeBounds, { - assert_matching_env_txn!(self, txn); + assert_eq_env_db_txn!(self, txn); let start_bound = match range.start_bound() { Bound::Included(bound) => { @@ -1002,7 +1002,7 @@ impl PolyDatabase { KC: BytesEncode<'a>, R: RangeBounds, { - assert_matching_env_txn!(self, txn); + assert_eq_env_db_txn!(self, txn); let start_bound = match range.start_bound() { Bound::Included(bound) => { @@ -1080,7 +1080,7 @@ impl PolyDatabase { KC: BytesEncode<'a>, R: RangeBounds, { - assert_matching_env_txn!(self, txn); + assert_eq_env_db_txn!(self, txn); let start_bound = match range.start_bound() { Bound::Included(bound) => { @@ -1171,7 +1171,7 @@ impl PolyDatabase { KC: BytesEncode<'a>, R: RangeBounds, { - assert_matching_env_txn!(self, txn); + assert_eq_env_db_txn!(self, txn); let start_bound = match range.start_bound() { Bound::Included(bound) => { @@ -1249,7 +1249,7 @@ impl PolyDatabase { where KC: BytesEncode<'a>, { - assert_matching_env_txn!(self, txn); + assert_eq_env_db_txn!(self, txn); let prefix_bytes = KC::bytes_encode(prefix).map_err(Error::Encoding)?; let prefix_bytes = prefix_bytes.into_owned(); @@ -1318,7 +1318,7 @@ impl PolyDatabase { where KC: BytesEncode<'a>, { - assert_matching_env_txn!(self, txn); + assert_eq_env_db_txn!(self, txn); let prefix_bytes = KC::bytes_encode(prefix).map_err(Error::Encoding)?; let prefix_bytes = prefix_bytes.into_owned(); @@ -1374,7 +1374,7 @@ impl PolyDatabase { where KC: BytesEncode<'a>, { - assert_matching_env_txn!(self, txn); + assert_eq_env_db_txn!(self, txn); let prefix_bytes = KC::bytes_encode(prefix).map_err(Error::Encoding)?; let prefix_bytes = prefix_bytes.into_owned(); @@ -1443,7 +1443,7 @@ impl PolyDatabase { where KC: BytesEncode<'a>, { - assert_matching_env_txn!(self, txn); + assert_eq_env_db_txn!(self, txn); let prefix_bytes = KC::bytes_encode(prefix).map_err(Error::Encoding)?; let prefix_bytes = prefix_bytes.into_owned(); @@ -1493,7 +1493,7 @@ impl PolyDatabase { KC: BytesEncode<'a>, DC: BytesEncode<'a>, { - assert_matching_env_txn!(self, txn); + assert_eq_env_db_txn!(self, txn); let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).map_err(Error::Encoding)?; let data_bytes: Cow<[u8]> = DC::bytes_encode(&data).map_err(Error::Encoding)?; @@ -1554,7 +1554,7 @@ impl PolyDatabase { KC: BytesEncode<'a>, F: FnMut(&mut ReservedSpace) -> io::Result<()>, { - assert_matching_env_txn!(self, txn); + assert_eq_env_db_txn!(self, txn); let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).map_err(Error::Encoding)?; let mut key_val = unsafe { crate::into_val(&key_bytes) }; @@ -1620,7 +1620,7 @@ impl PolyDatabase { KC: BytesEncode<'a>, DC: BytesEncode<'a>, { - assert_matching_env_txn!(self, txn); + assert_eq_env_db_txn!(self, txn); let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).map_err(Error::Encoding)?; let data_bytes: Cow<[u8]> = DC::bytes_encode(&data).map_err(Error::Encoding)?; @@ -1681,7 +1681,7 @@ impl PolyDatabase { where KC: BytesEncode<'a>, { - assert_matching_env_txn!(self, txn); + assert_eq_env_db_txn!(self, txn); let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).map_err(Error::Encoding)?; let mut key_val = unsafe { crate::into_val(&key_bytes) }; @@ -1749,7 +1749,7 @@ impl PolyDatabase { KC: BytesEncode<'a> + BytesDecode<'txn>, R: RangeBounds, { - assert_matching_env_txn!(self, txn); + assert_eq_env_db_txn!(self, txn); let mut count = 0; let mut iter = self.range_mut::(txn, range)?; @@ -1806,7 +1806,7 @@ impl PolyDatabase { /// # Ok(()) } /// ``` pub fn clear(&self, txn: &mut RwTxn) -> Result<()> { - assert_matching_env_txn!(self, txn); + assert_eq_env_db_txn!(self, txn); unsafe { mdb_result(ffi::mdb_drop(txn.txn.txn, self.dbi, 0)).map_err(Into::into) } } diff --git a/heed/src/env.rs b/heed/src/env.rs index dc5c20e0..91aacb1c 100644 --- a/heed/src/env.rs +++ b/heed/src/env.rs @@ -22,7 +22,9 @@ use synchronoise::event::SignalEvent; use crate::mdb::error::mdb_result; use crate::mdb::ffi; -use crate::{Database, Error, Flags, PolyDatabase, Result, RoCursor, RoTxn, RwTxn}; +use crate::{ + assert_eq_env_txn, Database, Error, Flags, PolyDatabase, Result, RoCursor, RoTxn, RwTxn, +}; /// The list of opened environments, the value is an optional environment, it is None /// when someone asks to close the environment, closing is a two-phase step, to make sure @@ -297,7 +299,7 @@ impl Drop for EnvInner { unsafe { let _ = ffi::mdb_env_close(self.env); } - // We signal to all the waiters that we have closed the env. + // We signal to all the waiters that the env is closed now. signal_event.signal(); } } @@ -442,6 +444,8 @@ impl Env { KC: 'static, DC: 'static, { + assert_eq_env_txn!(self, rtxn); + let types = (TypeId::of::(), TypeId::of::()); match self.raw_init_database(rtxn.txn, name, Some(types), false) { Ok(dbi) => Ok(Some(Database::new(self.env_mut_ptr() as _, dbi))), @@ -464,6 +468,8 @@ impl Env { rtxn: &RoTxn, name: Option<&str>, ) -> Result> { + assert_eq_env_txn!(self, rtxn); + match self.raw_init_database(rtxn.txn, name, None, false) { Ok(dbi) => Ok(Some(PolyDatabase::new(self.env_mut_ptr() as _, dbi))), Err(Error::Mdb(e)) if e.not_found() => Ok(None), @@ -489,6 +495,8 @@ impl Env { KC: 'static, DC: 'static, { + assert_eq_env_txn!(self, wtxn); + let types = (TypeId::of::(), TypeId::of::()); match self.raw_init_database(wtxn.txn.txn, name, Some(types), true) { Ok(dbi) => Ok(Database::new(self.env_mut_ptr() as _, dbi)), @@ -510,6 +518,8 @@ impl Env { wtxn: &mut RwTxn, name: Option<&str>, ) -> Result { + assert_eq_env_txn!(self, wtxn); + match self.raw_init_database(wtxn.txn.txn, name, None, true) { Ok(dbi) => Ok(PolyDatabase::new(self.env_mut_ptr() as _, dbi)), Err(e) => Err(e), diff --git a/heed/src/lib.rs b/heed/src/lib.rs index cefb56f3..2609b641 100644 --- a/heed/src/lib.rs +++ b/heed/src/lib.rs @@ -146,7 +146,7 @@ mod tests { } } -macro_rules! assert_matching_env_txn { +macro_rules! assert_eq_env_db_txn { ($database:ident, $txn:ident) => { assert!( $database.env_ident == $txn.env_mut_ptr() as usize, @@ -155,4 +155,13 @@ macro_rules! assert_matching_env_txn { }; } -pub(crate) use assert_matching_env_txn; +macro_rules! assert_eq_env_txn { + ($env:ident, $txn:ident) => { + assert!( + $env.env_mut_ptr() == $txn.env_mut_ptr(), + "The environment doesn't match the transaction's environment" + ); + }; +} + +pub(crate) use {assert_eq_env_db_txn, assert_eq_env_txn}; From 9db1ebc361752c59e27635c68bdd31c1de823d8f Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Sat, 24 Dec 2022 16:41:22 +0100 Subject: [PATCH 50/57] Fix the multi-env test --- heed/examples/multi-env.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/heed/examples/multi-env.rs b/heed/examples/multi-env.rs index 50331ecb..541fce36 100644 --- a/heed/examples/multi-env.rs +++ b/heed/examples/multi-env.rs @@ -21,19 +21,19 @@ fn main() -> Result<(), Box> { .max_dbs(3000) .open(env2_path)?; - let mut wtxn = env1.write_txn()?; - let db1: Database = env1.create_database(&mut wtxn, Some("hello"))?; + let mut wtxn1 = env1.write_txn()?; + let mut wtxn2 = env2.write_txn()?; + let db1: Database = env1.create_database(&mut wtxn1, Some("hello"))?; let db2: Database, OwnedType> = - env2.create_database(&mut wtxn, Some("hello"))?; + env2.create_database(&mut wtxn2, Some("hello"))?; // clear db - db1.clear(&mut wtxn)?; - wtxn.commit()?; + db1.clear(&mut wtxn1)?; + wtxn1.commit()?; // clear db - let mut wtxn = env2.write_txn()?; - db2.clear(&mut wtxn)?; - wtxn.commit()?; + db2.clear(&mut wtxn2)?; + wtxn2.commit()?; // ----- From 7c8afddaade36d8a88e818c1a0b55195f2ad28ed Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Wed, 11 Jan 2023 11:11:42 +0100 Subject: [PATCH 51/57] Change the LMDB source to point to mdb.master --- .gitmodules | 5 +- Cargo.toml | 2 +- heed/Cargo.toml | 4 +- heed/src/mdb/lmdb_error.rs | 14 +--- heed/src/mdb/lmdb_ffi.rs | 2 +- heed/src/mdb/lmdb_flags.rs | 2 +- .../.rustfmt.toml | 0 .../Cargo.toml | 10 +-- .../bindgen.rs | 0 .../build.rs | 0 lmdb-master-sys/lmdb | 1 + .../src/bindings.rs | 72 +----------------- .../src/lib.rs | 2 +- .../tests/fixtures/testdb-32/data.mdb | Bin .../tests/fixtures/testdb-32/lock.mdb | Bin .../tests/lmdb.rs | 0 .../tests/simple.rs | 4 +- lmdb-master3-sys/lmdb | 1 - 18 files changed, 22 insertions(+), 97 deletions(-) rename {lmdb-master3-sys => lmdb-master-sys}/.rustfmt.toml (100%) rename {lmdb-master3-sys => lmdb-master-sys}/Cargo.toml (82%) rename {lmdb-master3-sys => lmdb-master-sys}/bindgen.rs (100%) rename {lmdb-master3-sys => lmdb-master-sys}/build.rs (100%) create mode 160000 lmdb-master-sys/lmdb rename {lmdb-master3-sys => lmdb-master-sys}/src/bindings.rs (89%) rename {lmdb-master3-sys => lmdb-master-sys}/src/lib.rs (88%) rename {lmdb-master3-sys => lmdb-master-sys}/tests/fixtures/testdb-32/data.mdb (100%) rename {lmdb-master3-sys => lmdb-master-sys}/tests/fixtures/testdb-32/lock.mdb (100%) rename {lmdb-master3-sys => lmdb-master-sys}/tests/lmdb.rs (100%) rename {lmdb-master3-sys => lmdb-master-sys}/tests/simple.rs (96%) delete mode 160000 lmdb-master3-sys/lmdb diff --git a/.gitmodules b/.gitmodules index 2691a76f..e946c61f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,4 @@ -[submodule "lmdb-master3-sys/lmdb"] - path = lmdb-master3-sys/lmdb +[submodule "lmdb-master-sys/lmdb"] + path = lmdb-master-sys/lmdb url = https://github.com/LMDB/lmdb + branch = mdb.master diff --git a/Cargo.toml b/Cargo.toml index 1ea0bfb8..f88355d8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,2 +1,2 @@ [workspace] -members = ["lmdb-master3-sys", "heed", "heed-traits", "heed-types"] +members = ["lmdb-master-sys", "heed", "heed-traits", "heed-types"] diff --git a/heed/Cargo.toml b/heed/Cargo.toml index 600093b8..21179cae 100644 --- a/heed/Cargo.toml +++ b/heed/Cargo.toml @@ -16,7 +16,7 @@ byteorder = { version = "1.4.3", default-features = false } heed-traits = { version = "0.7.0", path = "../heed-traits" } heed-types = { version = "0.7.2", path = "../heed-types" } libc = "0.2.139" -lmdb-master3-sys = { version = "0.1.0", path = "../lmdb-master3-sys" } +lmdb-master-sys = { version = "0.1.0", path = "../lmdb-master-sys" } once_cell = "1.16.0" page_size = "0.5.0" serde = { version = "1.0.151", features = ["derive"], optional = true } @@ -36,7 +36,7 @@ url = "2.3.1" default = ["serde", "serde-bincode", "serde-json"] # Use the provided version of LMDB instead of the one that is installed on the system. -vendored = ["lmdb-master3-sys/vendored"] +vendored = ["lmdb-master-sys/vendored"] # The NO_TLS flag is automatically set on Env opening and # RoTxn implements the Sync trait. This allow the user to reference diff --git a/heed/src/mdb/lmdb_error.rs b/heed/src/mdb/lmdb_error.rs index 48734221..11674b2f 100644 --- a/heed/src/mdb/lmdb_error.rs +++ b/heed/src/mdb/lmdb_error.rs @@ -4,7 +4,7 @@ use std::os::raw::c_char; use std::{fmt, str}; use libc::c_int; -use lmdb_master3_sys as ffi; +use lmdb_master_sys as ffi; /// An LMDB error kind. #[derive(Debug, Copy, Clone, Eq, PartialEq)] @@ -55,12 +55,6 @@ pub enum Error { BadDbi, /// Unexpected problem - transaction should abort. Problem, - /// Page checksum incorrect. - BadChecksum, - /// Encryption/decryption failed. - CryptoFail, - /// Environment encryption mismatch. - EnvEncryption, /// Other error. Other(c_int), } @@ -94,9 +88,6 @@ impl Error { ffi::MDB_BAD_VALSIZE => Error::BadValSize, ffi::MDB_BAD_DBI => Error::BadDbi, ffi::MDB_PROBLEM => Error::Problem, - ffi::MDB_BAD_CHECKSUM => Error::BadChecksum, - ffi::MDB_CRYPTO_FAIL => Error::CryptoFail, - ffi::MDB_ENV_ENCRYPTION => Error::EnvEncryption, other => Error::Other(other), } } @@ -126,9 +117,6 @@ impl Error { Error::BadValSize => ffi::MDB_BAD_VALSIZE, Error::BadDbi => ffi::MDB_BAD_DBI, Error::Problem => ffi::MDB_PROBLEM, - Error::BadChecksum => ffi::MDB_BAD_CHECKSUM, - Error::CryptoFail => ffi::MDB_CRYPTO_FAIL, - Error::EnvEncryption => ffi::MDB_ENV_ENCRYPTION, Error::Other(err_code) => err_code, } } diff --git a/heed/src/mdb/lmdb_ffi.rs b/heed/src/mdb/lmdb_ffi.rs index d955f1d2..9f093db7 100644 --- a/heed/src/mdb/lmdb_ffi.rs +++ b/heed/src/mdb/lmdb_ffi.rs @@ -9,7 +9,7 @@ pub use ffi::{ MDB_cursor, MDB_dbi, MDB_env, MDB_envinfo, MDB_stat, MDB_txn, MDB_val, MDB_APPEND, MDB_CP_COMPACT, MDB_CREATE, MDB_CURRENT, MDB_RDONLY, MDB_RESERVE, }; -use lmdb_master3_sys as ffi; +use lmdb_master_sys as ffi; pub mod cursor_op { use super::ffi::{self, MDB_cursor_op}; diff --git a/heed/src/mdb/lmdb_flags.rs b/heed/src/mdb/lmdb_flags.rs index 9f842885..f11ec935 100644 --- a/heed/src/mdb/lmdb_flags.rs +++ b/heed/src/mdb/lmdb_flags.rs @@ -1,4 +1,4 @@ -use lmdb_master3_sys as ffi; +use lmdb_master_sys as ffi; /// LMDB flags (see for more details). #[derive(Debug, Clone, Copy, PartialEq, Eq)] diff --git a/lmdb-master3-sys/.rustfmt.toml b/lmdb-master-sys/.rustfmt.toml similarity index 100% rename from lmdb-master3-sys/.rustfmt.toml rename to lmdb-master-sys/.rustfmt.toml diff --git a/lmdb-master3-sys/Cargo.toml b/lmdb-master-sys/Cargo.toml similarity index 82% rename from lmdb-master3-sys/Cargo.toml rename to lmdb-master-sys/Cargo.toml index 6896f76d..1383f304 100644 --- a/lmdb-master3-sys/Cargo.toml +++ b/lmdb-master-sys/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "lmdb-master3-sys" +name = "lmdb-master-sys" # NB: When modifying, also modify html_root_url in lib.rs version = "0.1.0" authors = [ @@ -8,9 +8,9 @@ authors = [ "Victor Porof ", ] license = "Apache-2.0" -description = "Rust bindings for liblmdb on the mdb.master3 branch." -documentation = "https://docs.rs/lmdb-master3-sys" -repository = "https://github.com/meilisearch/heed/tree/main/lmdb-master3-sys" +description = "Rust bindings for liblmdb on the mdb.master branch." +documentation = "https://docs.rs/lmdb-master-sys" +repository = "https://github.com/meilisearch/heed/tree/main/lmdb-master-sys" keywords = ["LMDB", "database", "storage-engine", "bindings", "library"] categories = ["database", "external-ffi-bindings"] edition = "2021" @@ -19,7 +19,7 @@ edition = "2021" build = "build.rs" [lib] -name = "lmdb_master3_sys" +name = "lmdb_master_sys" [dependencies] libc = "0.2.139" diff --git a/lmdb-master3-sys/bindgen.rs b/lmdb-master-sys/bindgen.rs similarity index 100% rename from lmdb-master3-sys/bindgen.rs rename to lmdb-master-sys/bindgen.rs diff --git a/lmdb-master3-sys/build.rs b/lmdb-master-sys/build.rs similarity index 100% rename from lmdb-master3-sys/build.rs rename to lmdb-master-sys/build.rs diff --git a/lmdb-master-sys/lmdb b/lmdb-master-sys/lmdb new file mode 160000 index 00000000..3947014a --- /dev/null +++ b/lmdb-master-sys/lmdb @@ -0,0 +1 @@ +Subproject commit 3947014aed7ffe39a79991fa7fb5b234da47ad1a diff --git a/lmdb-master3-sys/src/bindings.rs b/lmdb-master-sys/src/bindings.rs similarity index 89% rename from lmdb-master3-sys/src/bindings.rs rename to lmdb-master-sys/src/bindings.rs index f3c10d20..53c24224 100644 --- a/lmdb-master3-sys/src/bindings.rs +++ b/lmdb-master-sys/src/bindings.rs @@ -1,14 +1,12 @@ /* automatically generated by rust-bindgen 0.63.0 */ pub const MDB_FMT_Z: &[u8; 2usize] = b"z\0"; -pub const MDB_RPAGE_CACHE: ::libc::c_uint = 1; pub const MDB_SIZE_MAX: u64 = 18446744073709551615; pub const MDB_VERSION_MAJOR: ::libc::c_uint = 0; pub const MDB_VERSION_MINOR: ::libc::c_uint = 9; -pub const MDB_VERSION_PATCH: ::libc::c_uint = 90; -pub const MDB_VERSION_DATE: &[u8; 12usize] = b"May 1, 2017\0"; +pub const MDB_VERSION_PATCH: ::libc::c_uint = 70; +pub const MDB_VERSION_DATE: &[u8; 18usize] = b"December 19, 2015\0"; pub const MDB_FIXEDMAP: ::libc::c_uint = 1; -pub const MDB_ENCRYPT: ::libc::c_uint = 8192; pub const MDB_NOSUBDIR: ::libc::c_uint = 16384; pub const MDB_NOSYNC: ::libc::c_uint = 65536; pub const MDB_RDONLY: ::libc::c_uint = 131072; @@ -20,7 +18,6 @@ pub const MDB_NOLOCK: ::libc::c_uint = 4194304; pub const MDB_NORDAHEAD: ::libc::c_uint = 8388608; pub const MDB_NOMEMINIT: ::libc::c_uint = 16777216; pub const MDB_PREVSNAPSHOT: ::libc::c_uint = 33554432; -pub const MDB_REMAP_CHUNKS: ::libc::c_uint = 67108864; pub const MDB_REVERSEKEY: ::libc::c_uint = 2; pub const MDB_DUPSORT: ::libc::c_uint = 4; pub const MDB_INTEGERKEY: ::libc::c_uint = 8; @@ -58,10 +55,7 @@ pub const MDB_BAD_TXN: ::libc::c_int = -30782; pub const MDB_BAD_VALSIZE: ::libc::c_int = -30781; pub const MDB_BAD_DBI: ::libc::c_int = -30780; pub const MDB_PROBLEM: ::libc::c_int = -30779; -pub const MDB_BAD_CHECKSUM: ::libc::c_int = -30778; -pub const MDB_CRYPTO_FAIL: ::libc::c_int = -30777; -pub const MDB_ENV_ENCRYPTION: ::libc::c_int = -30776; -pub const MDB_LAST_ERRCODE: ::libc::c_int = -30776; +pub const MDB_LAST_ERRCODE: ::libc::c_int = -30779; #[doc = "Unsigned type used for mapsize, entry counts and page/transaction IDs.\nIt is normally size_t, hence the name. Defining MDB_VL32 makes it\nuint64_t, but do not try this unless you know what you are doing.\n\n"] pub type mdb_size_t = usize; #[repr(C)] @@ -103,19 +97,6 @@ pub type MDB_rel_func = ::std::option::Option< relctx: *mut ::libc::c_void, ), >; -#[doc = "A callback function used to encrypt/decrypt pages in the env.\n\nEncrypt or decrypt the data in src and store the result in dst using the\nprovided key. The result must be the same number of bytes as the input.\nkey[1] is the initialization vector, and key[2] is the authentication\ndata, if any.\n\nReturns:\n\n* A non-zero error value on failure and 0 on success.\n\n# Arguments\n\n* `src` - The input data to be transformed. [Direction: In]\n* `dst` - Storage for the result. [Direction: In, Out]\n* `key` - An array of three values: key[0] is the encryption key, [Direction: In]\n* `encdec` - 1 to encrypt, 0 to decrypt. [Direction: In]\n\n"] -pub type MDB_enc_func = ::std::option::Option< - unsafe extern "C" fn( - src: *const MDB_val, - dst: *mut MDB_val, - key: *const MDB_val, - encdec: ::libc::c_int, - ) -> ::libc::c_int, ->; -#[doc = "A callback function used to checksum pages in the env.\n\nCompute the checksum of the data in src and store the result in dst,\nAn optional key may be used with keyed hash algorithms.\nparameter will be NULL if there is no key.\n\n# Arguments\n\n* `src` - The input data to be transformed. [Direction: In]\n* `dst` - Storage for the result. [Direction: In, Out]\n* `key` - An encryption key, if encryption was configured. This [Direction: In]\n\n"] -pub type MDB_sum_func = ::std::option::Option< - unsafe extern "C" fn(src: *const MDB_val, dst: *mut MDB_val, key: *const MDB_val), ->; #[doc = "Position at first key/data item\n\n"] pub const MDB_FIRST: MDB_cursor_op = 0; #[doc = "Position at first data item of current key.\nOnly for #MDB_DUPSORT\n\n"] @@ -279,10 +260,6 @@ extern "C" { #[doc = "Set the size of the memory map to use for this environment.\n\nThe size should be a multiple of the OS page size. The default is\n10485760 bytes. The size of the memory map is also the maximum size\nof the database. The value should be chosen as large as possible,\nto accommodate future growth of the database.\nThis function should be called after #mdb_env_create() and before #mdb_env_open().\nIt may be called at later times if no transactions are active in\nthis process. Note that the library does not check for this condition,\nthe caller must ensure it explicitly.\nThe new size takes effect immediately for the current process but\nwill not be persisted to any others until a write transaction has been\ncommitted by the current process. Also, only mapsize increases are\npersisted into the environment.\nIf the mapsize is increased by another process, and data has grown\nbeyond the range of the current mapsize, #mdb_txn_begin() will\nreturn #MDB_MAP_RESIZED. This function may be called with a size\nof zero to adopt the new size.\nAny attempt to set a size smaller than the space already consumed\nby the environment will be silently changed to the current size of the used space.\nerrors are:\n
    \n
  • EINVAL - an invalid parameter was specified, or the environment has\nan active write transaction.\n
\n\nReturns:\n\n* A non-zero error value on failure and 0 on success. Some possible\n\n# Arguments\n\n* `env` - An environment handle returned by #mdb_env_create() [Direction: In]\n* `size` - The size in bytes [Direction: In]\n\n"] pub fn mdb_env_set_mapsize(env: *mut MDB_env, size: mdb_size_t) -> ::libc::c_int; } -extern "C" { - #[doc = "Set the size of DB pages in bytes.\n\nThe size defaults to the OS page size. Smaller or larger values may be\ndesired depending on the size of keys and values being used. Also, an\nexplicit size may need to be set when using filesystems like ZFS which\ndon't use the OS page size.\n\n"] - pub fn mdb_env_set_pagesize(env: *mut MDB_env, size: ::libc::c_int) -> ::libc::c_int; -} extern "C" { #[doc = "Set the maximum number of threads/reader slots for the environment.\n\nThis defines the number of slots in the lock table that is used to track readers in the\nthe environment. The default is 126.\nStarting a read-only transaction normally ties a lock table slot to the\ncurrent thread until the environment closes or the thread exits. If\nMDB_NOTLS is in use, #mdb_txn_begin() instead ties the slot to the\nMDB_txn object until it or the #MDB_env object is destroyed.\nThis function may only be called after #mdb_env_create() and before #mdb_env_open().\nerrors are:\n
    \n
  • EINVAL - an invalid parameter was specified, or the environment is already open.\n
\n\nReturns:\n\n* A non-zero error value on failure and 0 on success. Some possible\n\n# Arguments\n\n* `env` - An environment handle returned by #mdb_env_create() [Direction: In]\n* `readers` - The maximum number of reader lock table slots [Direction: In]\n\n"] pub fn mdb_env_set_maxreaders(env: *mut MDB_env, readers: ::libc::c_uint) -> ::libc::c_int; @@ -315,23 +292,6 @@ extern "C" { #[doc = "Set or reset the assert() callback of the environment.\nDisabled if liblmdb is built with NDEBUG.\n\nReturns:\n\n* A non-zero error value on failure and 0 on success.\n\n# Arguments\n\n* `env` - An environment handle returned by #mdb_env_create(). [Direction: In]\n* `func` - An #MDB_assert_func function, or 0. [Direction: In]\n\n# Notes\n\n* This hack should become obsolete as lmdb's error handling matures.\n\n"] pub fn mdb_env_set_assert(env: *mut MDB_env, func: MDB_assert_func) -> ::libc::c_int; } -extern "C" { - #[doc = "Set encryption on an environment.\n\nThis must be called before #mdb_env_open().\nIt implicitly sets #MDB_REMAP_CHUNKS on the env.\nSet this to zero for unauthenticated encryption mechanisms.\n\nReturns:\n\n* A non-zero error value on failure and 0 on success.\n\n# Arguments\n\n* `env` - An environment handle returned by #mdb_env_create(). [Direction: In]\n* `func` - An #MDB_enc_func function. [Direction: In]\n* `key` - The encryption key. [Direction: In]\n* `size` - The size of authentication data in bytes, if any. [Direction: In]\n\n"] - pub fn mdb_env_set_encrypt( - env: *mut MDB_env, - func: MDB_enc_func, - key: *const MDB_val, - size: ::libc::c_uint, - ) -> ::libc::c_int; -} -extern "C" { - #[doc = "Set checksums on an environment.\n\nThis must be called before #mdb_env_open().\n\nReturns:\n\n* A non-zero error value on failure and 0 on success.\n\n# Arguments\n\n* `env` - An environment handle returned by #mdb_env_create(). [Direction: In]\n* `func` - An #MDB_sum_func function. [Direction: In]\n* `size` - The size of computed checksum values, in bytes. [Direction: In]\n\n"] - pub fn mdb_env_set_checksum( - env: *mut MDB_env, - func: MDB_sum_func, - size: ::libc::c_uint, - ) -> ::libc::c_int; -} extern "C" { #[doc = "Create a transaction for use with the environment.\n\nThe transaction handle may be discarded using #mdb_txn_abort() or #mdb_txn_commit().\nthread, and a thread may only have a single transaction at a time.\nIf #MDB_NOTLS is in use, this does not apply to read-only transactions.\nwill be a nested transaction, with the transaction indicated by \\b parent\nas its parent. Transactions may be nested to any level. A parent\ntransaction and its cursors may not issue any other operations than\nmdb_txn_commit and mdb_txn_abort while it has active child transactions.\nmust be set to 0 or by bitwise OR'ing together one or more of the\nvalues described here.\n
    \n
  • #MDB_RDONLY\nThis transaction will not perform any write operations.\n
  • #MDB_NOSYNC\nDon't flush system buffers to disk when committing this transaction.\n
  • #MDB_NOMETASYNC\nFlush system buffers but omit metadata flush when committing this transaction.\n
\nerrors are:\n
    \n
  • #MDB_PANIC - a fatal error occurred earlier and the environment\nmust be shut down.\n
  • #MDB_MAP_RESIZED - another process wrote data beyond this MDB_env's\nmapsize and this environment's map must be resized as well.\nSee #mdb_env_set_mapsize().\n
  • #MDB_READERS_FULL - a read-only transaction was requested and\nthe reader lock table is full. See #mdb_env_set_maxreaders().\n
  • ENOMEM - out of memory.\n
\n\nReturns:\n\n* A non-zero error value on failure and 0 on success. Some possible\n\n# Arguments\n\n* `env` - An environment handle returned by #mdb_env_create() [Direction: In]\n* `parent` - If this parameter is non-NULL, the new transaction [Direction: In]\n* `flags` - Special options for this transaction. This parameter [Direction: In]\n* `txn` - Address where the new #MDB_txn handle will be stored [Direction: In, Out]\n\n# Notes\n\n* A transaction and its cursors must only be used by a single\n* Cursors may not span transactions.\n\n"] pub fn mdb_txn_begin( @@ -366,7 +326,7 @@ extern "C" { pub fn mdb_txn_renew(txn: *mut MDB_txn) -> ::libc::c_int; } extern "C" { - #[doc = "Open a database in the environment.\n\nA database handle denotes the name and parameters of a database,\nindependently of whether such a database exists.\nThe database handle may be discarded by calling #mdb_dbi_close().\nThe old database handle is returned if the database was already open.\nThe handle may only be closed once.\nThe database handle will be private to the current transaction until\nthe transaction is successfully committed. If the transaction is\naborted the handle will be closed automatically.\nAfter a successful commit the handle will reside in the shared\nenvironment, and may be used by other transactions.\nThis function must not be called from multiple concurrent\ntransactions in the same process. A transaction that uses\nthis function must finish (either commit or abort) before\nany other transaction in the process may use this function.\nTo use named databases (with name != NULL), #mdb_env_set_maxdbs()\nmust be called before opening the environment. Database names are\nkeys in the unnamed database, and may be read but not written.\nIn LMDB 0.9 the NUL terminator was omitted.\ndatabase is needed in the environment, this value may be NULL.\nmust be set to 0 or by bitwise OR'ing together one or more of the\nvalues described here.\n
    \n
  • #MDB_REVERSEKEY\nKeys are strings to be compared in reverse order, from the end\nof the strings to the beginning. By default, Keys are treated as strings and\ncompared from beginning to end.\n
  • #MDB_DUPSORT\nDuplicate keys may be used in the database. (Or, from another perspective,\nkeys may have multiple data items, stored in sorted order.) By default\nkeys must be unique and may have only a single data item.\n
  • #MDB_INTEGERKEY\nKeys are binary integers in native byte order, either unsigned int\nor #mdb_size_t, and will be sorted as such.\n(lmdb expects 32-bit int <= size_t <= 32/64-bit mdb_size_t.)\nThe keys must all be of the same size.\n
  • #MDB_DUPFIXED\nThis flag may only be used in combination with #MDB_DUPSORT. This option\ntells the library that the data items for this database are all the same\nsize, which allows further optimizations in storage and retrieval. When\nall data items are the same size, the #MDB_GET_MULTIPLE, #MDB_NEXT_MULTIPLE\nand #MDB_PREV_MULTIPLE cursor operations may be used to retrieve multiple\nitems at once.\n
  • #MDB_INTEGERDUP\nThis option specifies that duplicate data items are binary integers,\nsimilar to #MDB_INTEGERKEY keys.\n
  • #MDB_REVERSEDUP\nThis option specifies that duplicate data items should be compared as\nstrings in reverse order.\n
  • #MDB_CREATE\nCreate the named database if it doesn't exist. This option is not\nallowed in a read-only transaction or a read-only environment.\n
\nerrors are:\n
    \n
  • #MDB_NOTFOUND - the specified database doesn't exist in the environment\nand #MDB_CREATE was not specified.\n
  • #MDB_DBS_FULL - too many databases have been opened. See #mdb_env_set_maxdbs().\n
\n\nReturns:\n\n* A non-zero error value on failure and 0 on success. Some possible\n\n# Arguments\n\n* `txn` - A transaction handle returned by #mdb_txn_begin() [Direction: In]\n* `name` - The name of the database to open. If only a single [Direction: In]\n* `flags` - Special options for this database. This parameter [Direction: In]\n* `dbi` - Address where the new #MDB_dbi handle will be stored [Direction: In, Out]\n\n# Notes\n\n* Names are C strings and stored with their NUL terminator included.\n\n"] + #[doc = "Open a database in the environment.\n\nA database handle denotes the name and parameters of a database,\nindependently of whether such a database exists.\nThe database handle may be discarded by calling #mdb_dbi_close().\nThe old database handle is returned if the database was already open.\nThe handle may only be closed once.\nThe database handle will be private to the current transaction until\nthe transaction is successfully committed. If the transaction is\naborted the handle will be closed automatically.\nAfter a successful commit the handle will reside in the shared\nenvironment, and may be used by other transactions.\nThis function must not be called from multiple concurrent\ntransactions in the same process. A transaction that uses\nthis function must finish (either commit or abort) before\nany other transaction in the process may use this function.\nTo use named databases (with name != NULL), #mdb_env_set_maxdbs()\nmust be called before opening the environment. Database names are\nkeys in the unnamed database, and may be read but not written.\ndatabase is needed in the environment, this value may be NULL.\nmust be set to 0 or by bitwise OR'ing together one or more of the\nvalues described here.\n
    \n
  • #MDB_REVERSEKEY\nKeys are strings to be compared in reverse order, from the end\nof the strings to the beginning. By default, Keys are treated as strings and\ncompared from beginning to end.\n
  • #MDB_DUPSORT\nDuplicate keys may be used in the database. (Or, from another perspective,\nkeys may have multiple data items, stored in sorted order.) By default\nkeys must be unique and may have only a single data item.\n
  • #MDB_INTEGERKEY\nKeys are binary integers in native byte order, either unsigned int\nor #mdb_size_t, and will be sorted as such.\n(lmdb expects 32-bit int <= size_t <= 32/64-bit mdb_size_t.)\nThe keys must all be of the same size.\n
  • #MDB_DUPFIXED\nThis flag may only be used in combination with #MDB_DUPSORT. This option\ntells the library that the data items for this database are all the same\nsize, which allows further optimizations in storage and retrieval. When\nall data items are the same size, the #MDB_GET_MULTIPLE, #MDB_NEXT_MULTIPLE\nand #MDB_PREV_MULTIPLE cursor operations may be used to retrieve multiple\nitems at once.\n
  • #MDB_INTEGERDUP\nThis option specifies that duplicate data items are binary integers,\nsimilar to #MDB_INTEGERKEY keys.\n
  • #MDB_REVERSEDUP\nThis option specifies that duplicate data items should be compared as\nstrings in reverse order.\n
  • #MDB_CREATE\nCreate the named database if it doesn't exist. This option is not\nallowed in a read-only transaction or a read-only environment.\n
\nerrors are:\n
    \n
  • #MDB_NOTFOUND - the specified database doesn't exist in the environment\nand #MDB_CREATE was not specified.\n
  • #MDB_DBS_FULL - too many databases have been opened. See #mdb_env_set_maxdbs().\n
\n\nReturns:\n\n* A non-zero error value on failure and 0 on success. Some possible\n\n# Arguments\n\n* `txn` - A transaction handle returned by #mdb_txn_begin() [Direction: In]\n* `name` - The name of the database to open. If only a single [Direction: In]\n* `flags` - Special options for this database. This parameter [Direction: In]\n* `dbi` - Address where the new #MDB_dbi handle will be stored [Direction: In, Out]\n\n"] pub fn mdb_dbi_open( txn: *mut MDB_txn, name: *const ::libc::c_char, @@ -466,10 +426,6 @@ extern "C" { #[doc = "Return the cursor's database handle.\n\n# Arguments\n\n* `cursor` - A cursor handle returned by #mdb_cursor_open() [Direction: In]\n\n"] pub fn mdb_cursor_dbi(cursor: *mut MDB_cursor) -> MDB_dbi; } -extern "C" { - #[doc = "Check if the cursor is pointing to a named database record.\n\nReturns:\n\n* 1 if current record is a named database, 0 otherwise.\n\n# Arguments\n\n* `cursor` - A cursor handle returned by #mdb_cursor_open() [Direction: In]\n\n"] - pub fn mdb_cursor_is_db(cursor: *mut MDB_cursor) -> ::libc::c_int; -} extern "C" { #[doc = "Retrieve by cursor.\n\nThis function retrieves key/data pairs from the database. The address and length\nof the key are returned in the object to which \\b key refers (except for the\ncase of the #MDB_SET option, in which the \\b key object is unchanged), and\nthe address and length of the data are returned in the object to which \\b data\nrefers.\nSee #mdb_get() for restrictions on using the output values.\nerrors are:\n
    \n
  • #MDB_NOTFOUND - no matching key found.\n
  • EINVAL - an invalid parameter was specified.\n
\n\nReturns:\n\n* A non-zero error value on failure and 0 on success. Some possible\n\n# Arguments\n\n* `cursor` - A cursor handle returned by #mdb_cursor_open() [Direction: In]\n* `key` - The key for a retrieved item [Direction: Out]\n* `data` - The data of a retrieved item [Direction: Out]\n* `op` - A cursor operation #MDB_cursor_op [Direction: In]\n\n"] pub fn mdb_cursor_get( @@ -530,23 +486,3 @@ extern "C" { #[doc = "Check for stale entries in the reader lock table.\n\nReturns:\n\n* 0 on success, non-zero on failure.\n\n# Arguments\n\n* `env` - An environment handle returned by #mdb_env_create() [Direction: In]\n* `dead` - Number of stale slots that were cleared [Direction: In, Out]\n\n"] pub fn mdb_reader_check(env: *mut MDB_env, dead: *mut ::libc::c_int) -> ::libc::c_int; } -#[doc = "A function for converting a string into an encryption key.\n\nprovide the space for the key.\n\nReturns:\n\n* 0 on success, non-zero on failure.\n\n# Arguments\n\n* `passwd` - The string to be converted. [Direction: In]\n* `key` - The resulting key. The caller must [Direction: Out]\n\n"] -pub type MDB_str2key_func = ::std::option::Option< - unsafe extern "C" fn(passwd: *const ::libc::c_char, key: *mut MDB_val) -> ::libc::c_int, ->; -#[doc = "A structure for dynamically loaded crypto modules.\n\nThis is the information that the command line tools expect\nin order to operate on encrypted or checksummed environments.\n\n"] -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct MDB_crypto_funcs { - pub mcf_str2key: MDB_str2key_func, - pub mcf_encfunc: MDB_enc_func, - pub mcf_sumfunc: MDB_sum_func, - #[doc = "The size of an encryption key, in bytes\n\n"] - pub mcf_keysize: ::libc::c_int, - #[doc = "The size of the MAC, for authenticated encryption\n\n"] - pub mcf_esumsize: ::libc::c_int, - #[doc = "The size of the checksum, for plain checksums\n\n"] - pub mcf_sumsize: ::libc::c_int, -} -#[doc = "The function that returns the #MDB_crypto_funcs structure.\n\nThe command line tools expect this function to be named \"MDB_crypto\".\nIt must be exported by the dynamic module so that the tools can use it.\n\nReturns:\n\n* A pointer to a #MDB_crypto_funcs structure.\n\n"] -pub type MDB_crypto_hooks = ::std::option::Option *mut MDB_crypto_funcs>; diff --git a/lmdb-master3-sys/src/lib.rs b/lmdb-master-sys/src/lib.rs similarity index 88% rename from lmdb-master3-sys/src/lib.rs rename to lmdb-master-sys/src/lib.rs index 9110ce16..947b880b 100644 --- a/lmdb-master3-sys/src/lib.rs +++ b/lmdb-master-sys/src/lib.rs @@ -2,7 +2,7 @@ #![allow(rustdoc::broken_intra_doc_links)] #![allow(non_camel_case_types)] #![allow(clippy::all)] -#![doc(html_root_url = "https://docs.rs/lmdb-master3-sys/0.1.0")] +#![doc(html_root_url = "https://docs.rs/lmdb-master-sys/0.1.0")] extern crate libc; diff --git a/lmdb-master3-sys/tests/fixtures/testdb-32/data.mdb b/lmdb-master-sys/tests/fixtures/testdb-32/data.mdb similarity index 100% rename from lmdb-master3-sys/tests/fixtures/testdb-32/data.mdb rename to lmdb-master-sys/tests/fixtures/testdb-32/data.mdb diff --git a/lmdb-master3-sys/tests/fixtures/testdb-32/lock.mdb b/lmdb-master-sys/tests/fixtures/testdb-32/lock.mdb similarity index 100% rename from lmdb-master3-sys/tests/fixtures/testdb-32/lock.mdb rename to lmdb-master-sys/tests/fixtures/testdb-32/lock.mdb diff --git a/lmdb-master3-sys/tests/lmdb.rs b/lmdb-master-sys/tests/lmdb.rs similarity index 100% rename from lmdb-master3-sys/tests/lmdb.rs rename to lmdb-master-sys/tests/lmdb.rs diff --git a/lmdb-master3-sys/tests/simple.rs b/lmdb-master-sys/tests/simple.rs similarity index 96% rename from lmdb-master3-sys/tests/simple.rs rename to lmdb-master-sys/tests/simple.rs index cabeb8b3..e82fb670 100644 --- a/lmdb-master3-sys/tests/simple.rs +++ b/lmdb-master-sys/tests/simple.rs @@ -1,4 +1,4 @@ -use lmdb_master3_sys::*; +use lmdb_master_sys::*; use std::ffi::c_void; use std::fs::{self, File}; @@ -9,7 +9,7 @@ use std::ptr; macro_rules! E { ($expr:expr) => {{ match $expr { - lmdb_master3_sys::MDB_SUCCESS => (), + lmdb_master_sys::MDB_SUCCESS => (), err_code => assert!(false, "Failed with code {}", err_code), } }}; diff --git a/lmdb-master3-sys/lmdb b/lmdb-master3-sys/lmdb deleted file mode 160000 index b9db2582..00000000 --- a/lmdb-master3-sys/lmdb +++ /dev/null @@ -1 +0,0 @@ -Subproject commit b9db2582cb31aa0ec88371db388095cc31ceb2f4 From d5bef4f971dda04d7ff5542c2805643687b1cb52 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Wed, 11 Jan 2023 11:34:22 +0100 Subject: [PATCH 52/57] Run all examples in the CI --- .github/workflows/{test.yml => rust.yml} | 26 +++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) rename .github/workflows/{test.yml => rust.yml} (61%) diff --git a/.github/workflows/test.yml b/.github/workflows/rust.yml similarity index 61% rename from .github/workflows/test.yml rename to .github/workflows/rust.yml index 7c2847f1..818ea4ba 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/rust.yml @@ -1,7 +1,7 @@ --- on: [pull_request] -name: Cargo test +name: Rust jobs: check: name: Test the heed project @@ -28,6 +28,30 @@ jobs: cargo clean cargo test + examples: + name: Run the heed examples + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macos-latest] + include: + - os: ubuntu-latest + - os: macos-latest + + steps: + - uses: actions/checkout@v2 + with: + submodules: recursive + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + - name: Run the examples + run: | + cargo clean + cargo run --example 2>&1 | grep -E '^ ' | xargs -n1 cargo run --example + fmt: name: Ensure the heed project is formatted runs-on: ubuntu-latest From df71fed99482b852f3fdaaf7f9e1c0c4498c014d Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Wed, 11 Jan 2023 11:40:39 +0100 Subject: [PATCH 53/57] Remove the feature and always use the vendored version --- README.md | 13 ------------ heed/Cargo.toml | 3 --- lmdb-master-sys/Cargo.toml | 7 +++---- lmdb-master-sys/build.rs | 42 ++++++++++++++++++-------------------- 4 files changed, 23 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index 0e65a729..1fb16414 100644 --- a/README.md +++ b/README.md @@ -13,11 +13,6 @@ This library is able to serialize all kind of types, not just bytes slices, even Go check out [the examples](heed/examples/). -## Vendoring - -By default, if LMDB is installed on the system, this crate will attempt to make use of the system-available LMDB. -To force installation from source, build this crate with the `vendored` feature. - ## Building from Source ### Using the system LMDB if available @@ -35,11 +30,3 @@ However, if you already cloned it and forgot about the initialising the submodul ```bash git submodule update --init ``` - -### Always vendoring - -```bash -git clone --recursive https://github.com/meilisearch/heed.git -cd heed -cargo build --features vendored -``` diff --git a/heed/Cargo.toml b/heed/Cargo.toml index 21179cae..c7db9f46 100644 --- a/heed/Cargo.toml +++ b/heed/Cargo.toml @@ -35,9 +35,6 @@ url = "2.3.1" # like the `EnvOpenOptions` struct. default = ["serde", "serde-bincode", "serde-json"] -# Use the provided version of LMDB instead of the one that is installed on the system. -vendored = ["lmdb-master-sys/vendored"] - # The NO_TLS flag is automatically set on Env opening and # RoTxn implements the Sync trait. This allow the user to reference # a read-only transaction from multiple threads at the same time. diff --git a/lmdb-master-sys/Cargo.toml b/lmdb-master-sys/Cargo.toml index 1383f304..92d601bb 100644 --- a/lmdb-master-sys/Cargo.toml +++ b/lmdb-master-sys/Cargo.toml @@ -32,7 +32,6 @@ pkg-config = "0.3.26" [features] default = [] -vendored = [] -with-asan = ["vendored"] -with-fuzzer = ["vendored"] -with-fuzzer-no-link = ["vendored"] +with-asan = [] +with-fuzzer = [] +with-fuzzer-no-link = [] diff --git a/lmdb-master-sys/build.rs b/lmdb-master-sys/build.rs index 150faee6..2d14063a 100644 --- a/lmdb-master-sys/build.rs +++ b/lmdb-master-sys/build.rs @@ -31,27 +31,25 @@ fn main() { warn!("Building with `-fsanitize=fuzzer`."); } - if cfg!(feature = "vendored") || pkg_config::find_library("lmdb").is_err() { - let mut builder = cc::Build::new(); - - builder - .file(lmdb.join("mdb.c")) - .file(lmdb.join("midl.c")) - // https://github.com/mozilla/lmdb/blob/b7df2cac50fb41e8bd16aab4cc5fd167be9e032a/libraries/liblmdb/Makefile#L23 - .flag_if_supported("-Wno-unused-parameter") - .flag_if_supported("-Wbad-function-cast") - .flag_if_supported("-Wuninitialized"); - - if cfg!(feature = "with-asan") { - builder.flag("-fsanitize=address"); - } - - if cfg!(feature = "with-fuzzer") { - builder.flag("-fsanitize=fuzzer"); - } else if cfg!(feature = "with-fuzzer-no-link") { - builder.flag("-fsanitize=fuzzer-no-link"); - } - - builder.compile("liblmdb.a") + let mut builder = cc::Build::new(); + + builder + .file(lmdb.join("mdb.c")) + .file(lmdb.join("midl.c")) + // https://github.com/mozilla/lmdb/blob/b7df2cac50fb41e8bd16aab4cc5fd167be9e032a/libraries/liblmdb/Makefile#L23 + .flag_if_supported("-Wno-unused-parameter") + .flag_if_supported("-Wbad-function-cast") + .flag_if_supported("-Wuninitialized"); + + if cfg!(feature = "with-asan") { + builder.flag("-fsanitize=address"); } + + if cfg!(feature = "with-fuzzer") { + builder.flag("-fsanitize=fuzzer"); + } else if cfg!(feature = "with-fuzzer-no-link") { + builder.flag("-fsanitize=fuzzer-no-link"); + } + + builder.compile("liblmdb.a") } From aa42e910146f837b9615223e55027208d281440a Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Wed, 11 Jan 2023 11:49:46 +0100 Subject: [PATCH 54/57] Do not prefix features by _with_ --- lmdb-master-sys/Cargo.toml | 6 +++--- lmdb-master-sys/build.rs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lmdb-master-sys/Cargo.toml b/lmdb-master-sys/Cargo.toml index 92d601bb..1a8946be 100644 --- a/lmdb-master-sys/Cargo.toml +++ b/lmdb-master-sys/Cargo.toml @@ -32,6 +32,6 @@ pkg-config = "0.3.26" [features] default = [] -with-asan = [] -with-fuzzer = [] -with-fuzzer-no-link = [] +asan = [] +fuzzer = [] +fuzzer-no-link = [] diff --git a/lmdb-master-sys/build.rs b/lmdb-master-sys/build.rs index 2d14063a..a042d765 100644 --- a/lmdb-master-sys/build.rs +++ b/lmdb-master-sys/build.rs @@ -41,13 +41,13 @@ fn main() { .flag_if_supported("-Wbad-function-cast") .flag_if_supported("-Wuninitialized"); - if cfg!(feature = "with-asan") { + if cfg!(feature = "asan") { builder.flag("-fsanitize=address"); } - if cfg!(feature = "with-fuzzer") { + if cfg!(feature = "fuzzer") { builder.flag("-fsanitize=fuzzer"); - } else if cfg!(feature = "with-fuzzer-no-link") { + } else if cfg!(feature = "fuzzer-no-link") { builder.flag("-fsanitize=fuzzer-no-link"); } From 30ded883a43f927cae3c7d615e912d761bc8a528 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Wed, 11 Jan 2023 11:53:44 +0100 Subject: [PATCH 55/57] Add POSIX semaphores Cargo feature Co-authored-by: GregoryConrad --- heed/Cargo.toml | 9 +++++++++ lmdb-master-sys/Cargo.toml | 1 + lmdb-master-sys/build.rs | 4 ++++ 3 files changed, 14 insertions(+) diff --git a/heed/Cargo.toml b/heed/Cargo.toml index c7db9f46..d16e1957 100644 --- a/heed/Cargo.toml +++ b/heed/Cargo.toml @@ -49,3 +49,12 @@ preserve_order = ["heed-types/preserve_order"] arbitrary_precision = ["heed-types/arbitrary_precision"] raw_value = ["heed-types/raw_value"] unbounded_depth = ["heed-types/unbounded_depth"] + +# Whether to tell LMDB to use POSIX semaphores during compilation +# (instead of the default, which are System V semaphores). +# POSIX semaphores are required for Apple's App Sandbox on iOS & macOS, +# and are possibly faster and more appropriate for single-process use. +# There are tradeoffs for both POSIX and SysV semaphores; which you +# should look into before enabling this feature. Also, see here: +# +posix-sem = ["lmdb-master-sys/posix-sem"] diff --git a/lmdb-master-sys/Cargo.toml b/lmdb-master-sys/Cargo.toml index 1a8946be..6e4bf8b6 100644 --- a/lmdb-master-sys/Cargo.toml +++ b/lmdb-master-sys/Cargo.toml @@ -35,3 +35,4 @@ default = [] asan = [] fuzzer = [] fuzzer-no-link = [] +posix-sem = [] diff --git a/lmdb-master-sys/build.rs b/lmdb-master-sys/build.rs index a042d765..2d57321e 100644 --- a/lmdb-master-sys/build.rs +++ b/lmdb-master-sys/build.rs @@ -41,6 +41,10 @@ fn main() { .flag_if_supported("-Wbad-function-cast") .flag_if_supported("-Wuninitialized"); + if cfg!(feature = "posix-sem") { + builder.define("MDB_USE_POSIX_SEM", None); + } + if cfg!(feature = "asan") { builder.flag("-fsanitize=address"); } From 466e55b2f582fe39205756ca57894d2921f07ac1 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Wed, 11 Jan 2023 11:58:30 +0100 Subject: [PATCH 56/57] Add a README to the lmdb-master-sys crate --- lmdb-master-sys/Cargo.toml | 1 + lmdb-master-sys/README.md | 3 +++ 2 files changed, 4 insertions(+) create mode 100644 lmdb-master-sys/README.md diff --git a/lmdb-master-sys/Cargo.toml b/lmdb-master-sys/Cargo.toml index 6e4bf8b6..afda7a9e 100644 --- a/lmdb-master-sys/Cargo.toml +++ b/lmdb-master-sys/Cargo.toml @@ -11,6 +11,7 @@ license = "Apache-2.0" description = "Rust bindings for liblmdb on the mdb.master branch." documentation = "https://docs.rs/lmdb-master-sys" repository = "https://github.com/meilisearch/heed/tree/main/lmdb-master-sys" +readme = "README.md" keywords = ["LMDB", "database", "storage-engine", "bindings", "library"] categories = ["database", "external-ffi-bindings"] edition = "2021" diff --git a/lmdb-master-sys/README.md b/lmdb-master-sys/README.md new file mode 100644 index 00000000..7612705c --- /dev/null +++ b/lmdb-master-sys/README.md @@ -0,0 +1,3 @@ +# lmdb-master-sys + +Rust bindings for liblmdb on the mdb.master branch. From abdb33423ce1dda15ba3c1042906d6511b03d9e0 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Wed, 11 Jan 2023 12:04:33 +0100 Subject: [PATCH 57/57] Change the heed, heed-traits and heed-types version to 0.20.0-alpha.0 --- heed-traits/Cargo.toml | 2 +- heed-types/Cargo.toml | 4 ++-- heed/Cargo.toml | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/heed-traits/Cargo.toml b/heed-traits/Cargo.toml index 2ccffee8..97397d4a 100644 --- a/heed-traits/Cargo.toml +++ b/heed-traits/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "heed-traits" -version = "0.7.0" +version = "0.20.0-alpha.0" authors = ["Kerollmops "] description = "The traits used inside of the fully typed LMDB wrapper, heed" license = "MIT" diff --git a/heed-types/Cargo.toml b/heed-types/Cargo.toml index e7acc654..5cc2c1b4 100644 --- a/heed-types/Cargo.toml +++ b/heed-types/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "heed-types" -version = "0.7.2" +version = "0.20.0-alpha.0" authors = ["Kerollmops "] description = "The types used with the fully typed LMDB wrapper, heed" license = "MIT" @@ -12,7 +12,7 @@ edition = "2021" bincode = { version = "1.3.3", optional = true } bytemuck = { version = "1.12.3", features = ["extern_crate_alloc", "extern_crate_std"] } byteorder = "1.4.3" -heed-traits = { version = "0.7.0", path = "../heed-traits" } +heed-traits = { version = "0.20.0-alpha.0", path = "../heed-traits" } serde = { version = "1.0.151", optional = true } serde_json = { version = "1.0.91", optional = true } diff --git a/heed/Cargo.toml b/heed/Cargo.toml index d16e1957..45167b6b 100644 --- a/heed/Cargo.toml +++ b/heed/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "heed" -version = "0.12.1" +version = "0.20.0-alpha.0" authors = ["Kerollmops "] description = "A fully typed LMDB wrapper with minimum overhead" license = "MIT" @@ -13,8 +13,8 @@ edition = "2021" [dependencies] bytemuck = "1.12.3" byteorder = { version = "1.4.3", default-features = false } -heed-traits = { version = "0.7.0", path = "../heed-traits" } -heed-types = { version = "0.7.2", path = "../heed-types" } +heed-traits = { version = "0.20.0-alpha.0", path = "../heed-traits" } +heed-types = { version = "0.20.0-alpha.0", path = "../heed-types" } libc = "0.2.139" lmdb-master-sys = { version = "0.1.0", path = "../lmdb-master-sys" } once_cell = "1.16.0"