From ff9f7545af30b49c1d86637c5886ff7b2d9a36b4 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Fri, 21 Jul 2023 15:59:22 +0200 Subject: [PATCH 1/6] Fix clippy warnings --- heed/src/env.rs | 20 ++++++++++---------- heed/src/iterator/mod.rs | 1 + lmdb-master-sys/tests/lmdb.rs | 10 ++++------ lmdb-master-sys/tests/simple.rs | 25 +++++++------------------ 4 files changed, 22 insertions(+), 34 deletions(-) diff --git a/heed/src/env.rs b/heed/src/env.rs index 48cd2992..ab3a1496 100644 --- a/heed/src/env.rs +++ b/heed/src/env.rs @@ -813,7 +813,7 @@ mod tests { let env = EnvOpenOptions::new() .map_size(10 * 1024 * 1024) // 10MB .max_dbs(30) - .open(&dir.path()) + .open(dir.path()) .unwrap(); // Force a thread to keep the env for 1 second. @@ -847,7 +847,7 @@ mod tests { eprintln!("env closed successfully"); // Make sure we don't have a reference to the env - assert!(env_closing_event(&dir.path()).is_none()); + assert!(env_closing_event(dir.path()).is_none()); } #[test] @@ -855,12 +855,12 @@ mod tests { let dir = tempfile::tempdir().unwrap(); let _env = EnvOpenOptions::new() .map_size(10 * 1024 * 1024) // 10MB - .open(&dir.path()) + .open(dir.path()) .unwrap(); let result = EnvOpenOptions::new() .map_size(12 * 1024 * 1024) // 12MB - .open(&dir.path()); + .open(dir.path()); assert!(matches!(result, Err(Error::BadOpenOptions { .. }))); } @@ -888,7 +888,7 @@ mod tests { envbuilder.map_size(10 * 1024 * 1024); // 10MB envbuilder.max_dbs(10); unsafe { envbuilder.flag(crate::Flag::WriteMap) }; - let env = envbuilder.open(&dir.path()).unwrap(); + let env = envbuilder.open(dir.path()).unwrap(); let mut wtxn = env.write_txn().unwrap(); let _db = env.create_database::(&mut wtxn, Some("my-super-db")).unwrap(); @@ -900,7 +900,7 @@ mod tests { let dir = tempfile::tempdir().unwrap(); let mut envbuilder = EnvOpenOptions::new(); unsafe { envbuilder.flag(crate::Flag::NoSubDir) }; - let _env = envbuilder.open(&dir.path().join("data.mdb")).unwrap(); + let _env = envbuilder.open(dir.path().join("data.mdb")).unwrap(); } #[test] @@ -909,7 +909,7 @@ mod tests { let env = EnvOpenOptions::new() .map_size(10 * 1024 * 1024) // 10MB .max_dbs(10) - .open(&dir.path()) + .open(dir.path()) .unwrap(); let mut wtxn = env.write_txn().unwrap(); @@ -927,7 +927,7 @@ mod tests { let env = EnvOpenOptions::new() .map_size(10 * 1024 * 1024) // 10MB .max_dbs(10) - .open(&dir.path()) + .open(dir.path()) .unwrap(); // we first create a database @@ -940,7 +940,7 @@ mod tests { let env = EnvOpenOptions::new() .map_size(10 * 1024 * 1024) // 10MB .max_dbs(10) - .open(&dir.path()) + .open(dir.path()) .unwrap(); let rtxn = env.read_txn().unwrap(); @@ -951,7 +951,7 @@ mod tests { #[test] fn resize_database() { let dir = tempfile::tempdir().unwrap(); - let env = EnvOpenOptions::new().map_size(9 * 4096).max_dbs(1).open(&dir.path()).unwrap(); + let env = EnvOpenOptions::new().map_size(9 * 4096).max_dbs(1).open(dir.path()).unwrap(); let mut wtxn = env.write_txn().unwrap(); let db = env.create_database::(&mut wtxn, Some("my-super-db")).unwrap(); diff --git a/heed/src/iterator/mod.rs b/heed/src/iterator/mod.rs index 4b90fff0..964a0872 100644 --- a/heed/src/iterator/mod.rs +++ b/heed/src/iterator/mod.rs @@ -203,6 +203,7 @@ mod tests { let iter = db.range(&wtxn, &range).unwrap(); assert_eq!(iter.last().transpose().unwrap(), None); + #[allow(clippy::reversed_empty_ranges)] let range = 2..=1; let iter = db.range(&wtxn, &range).unwrap(); assert_eq!(iter.last().transpose().unwrap(), None); diff --git a/lmdb-master-sys/tests/lmdb.rs b/lmdb-master-sys/tests/lmdb.rs index 7279ce07..6628a2d5 100644 --- a/lmdb-master-sys/tests/lmdb.rs +++ b/lmdb-master-sys/tests/lmdb.rs @@ -9,12 +9,10 @@ fn test_lmdb() { lmdb.push("libraries"); lmdb.push("liblmdb"); - let make_cmd = Command::new("make") - .current_dir(&lmdb) - .status() - .expect("failed to execute process"); + let make_cmd = + Command::new("make").current_dir(&lmdb).status().expect("failed to execute process"); - assert_eq!(make_cmd.success(), true); + assert!(make_cmd.success()); let make_test_cmd = Command::new("make") .arg("test") @@ -22,5 +20,5 @@ fn test_lmdb() { .status() .expect("failed to execute process"); - assert_eq!(make_test_cmd.success(), true); + assert!(make_test_cmd.success()); } diff --git a/lmdb-master-sys/tests/simple.rs b/lmdb-master-sys/tests/simple.rs index 9cf0bd4b..a6ceeea8 100644 --- a/lmdb-master-sys/tests/simple.rs +++ b/lmdb-master-sys/tests/simple.rs @@ -1,10 +1,10 @@ -use cstr::cstr; -use lmdb_master_sys::*; - use std::ffi::{c_void, CString}; use std::fs::{self, File}; use std::ptr; +use cstr::cstr; +use lmdb_master_sys::*; + // https://github.com/victorporof/lmdb/blob/mdb.master/libraries/liblmdb/moz-test.c macro_rules! E { @@ -46,14 +46,8 @@ 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 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 = cstr!("foo").as_ptr() as *mut c_void; let dval = cstr!("bar").as_ptr() as *mut c_void; @@ -62,15 +56,10 @@ fn test_simple(env_path: &str) { E!(mdb_env_create(&mut env)); E!(mdb_env_set_maxdbs(env, 2)); let env_path = CString::new(env_path).unwrap(); - E!(mdb_env_open(env, env_path.as_ptr(), 0, 0664)); + E!(mdb_env_open(env, env_path.as_ptr(), 0, 0o664)); E!(mdb_txn_begin(env, ptr::null_mut(), 0, &mut txn)); - E!(mdb_dbi_open( - txn, - cstr!("subdb").as_ptr(), - MDB_CREATE, - &mut dbi - )); + E!(mdb_dbi_open(txn, cstr!("subdb").as_ptr(), MDB_CREATE, &mut dbi)); E!(mdb_txn_commit(txn)); key.mv_size = 3; From 19734f4911eb8996f40dfa8a2fac6aa45a41d233 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Fri, 21 Jul 2023 16:40:00 +0200 Subject: [PATCH 2/6] Remove the mutable requirement of most of the heed methods --- heed/src/db/polymorph.rs | 27 ++++++++++++--------------- heed/src/db/uniform.rs | 24 ++++++++++++------------ heed/src/env.rs | 20 +++++++++++--------- 3 files changed, 35 insertions(+), 36 deletions(-) diff --git a/heed/src/db/polymorph.rs b/heed/src/db/polymorph.rs index 7b34135e..13ca24e9 100644 --- a/heed/src/db/polymorph.rs +++ b/heed/src/db/polymorph.rs @@ -756,7 +756,7 @@ impl PolyDatabase { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn iter_mut<'txn, KC, DC>(&self, txn: &'txn mut RwTxn) -> Result> { + pub fn iter_mut<'txn, KC, DC>(&self, txn: &'txn RwTxn) -> Result> { assert_eq_env_db_txn!(self, txn); RwCursor::new(txn, self.dbi).map(|cursor| RwIter::new(cursor)) @@ -854,10 +854,7 @@ impl PolyDatabase { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn rev_iter_mut<'txn, KC, DC>( - &self, - txn: &'txn mut RwTxn, - ) -> Result> { + pub fn rev_iter_mut<'txn, KC, DC>(&self, txn: &'txn RwTxn) -> Result> { assert_eq_env_db_txn!(self, txn); RwCursor::new(txn, self.dbi).map(|cursor| RwRevIter::new(cursor)) @@ -995,7 +992,7 @@ impl PolyDatabase { /// ``` pub fn range_mut<'a, 'txn, KC, DC, R>( &self, - txn: &'txn mut RwTxn, + txn: &'txn RwTxn, range: &'a R, ) -> Result> where @@ -1164,7 +1161,7 @@ impl PolyDatabase { /// ``` pub fn rev_range_mut<'a, 'txn, KC, DC, R>( &self, - txn: &'txn mut RwTxn, + txn: &'txn RwTxn, range: &'a R, ) -> Result> where @@ -1312,7 +1309,7 @@ impl PolyDatabase { /// ``` pub fn prefix_iter_mut<'a, 'txn, KC, DC>( &self, - txn: &'txn mut RwTxn, + txn: &'txn RwTxn, prefix: &'a KC::EItem, ) -> Result> where @@ -1437,7 +1434,7 @@ impl PolyDatabase { /// ``` pub fn rev_prefix_iter_mut<'a, 'txn, KC, DC>( &self, - txn: &'txn mut RwTxn, + txn: &'txn RwTxn, prefix: &'a KC::EItem, ) -> Result> where @@ -1485,7 +1482,7 @@ impl PolyDatabase { /// ``` pub fn put<'a, KC, DC>( &self, - txn: &mut RwTxn, + txn: &RwTxn, key: &'a KC::EItem, data: &'a DC::EItem, ) -> Result<()> @@ -1545,7 +1542,7 @@ impl PolyDatabase { /// ``` pub fn put_reserved<'a, KC, F>( &self, - txn: &mut RwTxn, + txn: &RwTxn, key: &'a KC::EItem, data_size: usize, mut write_func: F, @@ -1615,7 +1612,7 @@ impl PolyDatabase { /// ``` pub fn append<'a, KC, DC>( &self, - txn: &mut RwTxn, + txn: &RwTxn, key: &'a KC::EItem, data: &'a DC::EItem, ) -> Result<()> @@ -1680,7 +1677,7 @@ impl PolyDatabase { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn delete<'a, KC>(&self, txn: &mut RwTxn, key: &'a KC::EItem) -> Result + pub fn delete<'a, KC>(&self, txn: &RwTxn, key: &'a KC::EItem) -> Result where KC: BytesEncode<'a>, { @@ -1747,7 +1744,7 @@ impl PolyDatabase { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn delete_range<'a, 'txn, KC, R>(&self, txn: &'txn mut RwTxn, range: &'a R) -> Result + pub fn delete_range<'a, 'txn, KC, R>(&self, txn: &'txn RwTxn, range: &'a R) -> Result where KC: BytesEncode<'a> + BytesDecode<'txn>, R: RangeBounds, @@ -1808,7 +1805,7 @@ impl PolyDatabase { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn clear(&self, txn: &mut RwTxn) -> Result<()> { + pub fn clear(&self, txn: &RwTxn) -> Result<()> { 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/db/uniform.rs b/heed/src/db/uniform.rs index 7b5c045a..03888319 100644 --- a/heed/src/db/uniform.rs +++ b/heed/src/db/uniform.rs @@ -647,7 +647,7 @@ impl Database { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn iter_mut<'txn>(&self, txn: &'txn mut RwTxn) -> Result> { + pub fn iter_mut<'txn>(&self, txn: &'txn RwTxn) -> Result> { self.dyndb.iter_mut::(txn) } @@ -741,7 +741,7 @@ impl Database { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn rev_iter_mut<'txn>(&self, txn: &'txn mut RwTxn) -> Result> { + pub fn rev_iter_mut<'txn>(&self, txn: &'txn RwTxn) -> Result> { self.dyndb.rev_iter_mut::(txn) } @@ -851,7 +851,7 @@ impl Database { /// ``` pub fn range_mut<'a, 'txn, R>( &self, - txn: &'txn mut RwTxn, + txn: &'txn RwTxn, range: &'a R, ) -> Result> where @@ -968,7 +968,7 @@ impl Database { /// ``` pub fn rev_range_mut<'a, 'txn, R>( &self, - txn: &'txn mut RwTxn, + txn: &'txn RwTxn, range: &'a R, ) -> Result> where @@ -1086,7 +1086,7 @@ impl Database { /// ``` pub fn prefix_iter_mut<'a, 'txn>( &self, - txn: &'txn mut RwTxn, + txn: &'txn RwTxn, prefix: &'a KC::EItem, ) -> Result> where @@ -1203,7 +1203,7 @@ impl Database { /// ``` pub fn rev_prefix_iter_mut<'a, 'txn>( &self, - txn: &'txn mut RwTxn, + txn: &'txn RwTxn, prefix: &'a KC::EItem, ) -> Result> where @@ -1245,7 +1245,7 @@ impl Database { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn put<'a>(&self, txn: &mut RwTxn, key: &'a KC::EItem, data: &'a DC::EItem) -> Result<()> + pub fn put<'a>(&self, txn: &RwTxn, key: &'a KC::EItem, data: &'a DC::EItem) -> Result<()> where KC: BytesEncode<'a>, DC: BytesEncode<'a>, @@ -1289,7 +1289,7 @@ impl Database { /// ``` pub fn put_reserved<'a, F>( &self, - txn: &mut RwTxn, + txn: &RwTxn, key: &'a KC::EItem, data_size: usize, write_func: F, @@ -1340,7 +1340,7 @@ impl Database { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn append<'a>(&self, txn: &mut RwTxn, key: &'a KC::EItem, data: &'a DC::EItem) -> Result<()> + pub fn append<'a>(&self, txn: &RwTxn, key: &'a KC::EItem, data: &'a DC::EItem) -> Result<()> where KC: BytesEncode<'a>, DC: BytesEncode<'a>, @@ -1389,7 +1389,7 @@ impl Database { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn delete<'a>(&self, txn: &mut RwTxn, key: &'a KC::EItem) -> Result + pub fn delete<'a>(&self, txn: &RwTxn, key: &'a KC::EItem) -> Result where KC: BytesEncode<'a>, { @@ -1444,7 +1444,7 @@ impl Database { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn delete_range<'a, 'txn, R>(&self, txn: &'txn mut RwTxn, range: &'a R) -> Result + pub fn delete_range<'a, 'txn, R>(&self, txn: &'txn RwTxn, range: &'a R) -> Result where KC: BytesEncode<'a> + BytesDecode<'txn>, R: RangeBounds, @@ -1492,7 +1492,7 @@ impl Database { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn clear(&self, txn: &mut RwTxn) -> Result<()> { + pub fn clear(&self, txn: &RwTxn) -> Result<()> { self.dyndb.clear(txn) } diff --git a/heed/src/env.rs b/heed/src/env.rs index ab3a1496..0a742618 100644 --- a/heed/src/env.rs +++ b/heed/src/env.rs @@ -951,34 +951,36 @@ mod tests { #[test] fn resize_database() { let dir = tempfile::tempdir().unwrap(); - let env = EnvOpenOptions::new().map_size(9 * 4096).max_dbs(1).open(dir.path()).unwrap(); + let page_size = page_size::get(); + let env = + EnvOpenOptions::new().map_size(9 * page_size).max_dbs(1).open(dir.path()).unwrap(); let mut wtxn = env.write_txn().unwrap(); let db = env.create_database::(&mut wtxn, Some("my-super-db")).unwrap(); wtxn.commit().unwrap(); - let mut wtxn = env.write_txn().unwrap(); + let wtxn = env.write_txn().unwrap(); for i in 0..64 { - db.put(&mut wtxn, &i.to_string(), "world").unwrap(); + db.put(&wtxn, &i.to_string(), "world").unwrap(); } wtxn.commit().unwrap(); - let mut wtxn = env.write_txn().unwrap(); + let wtxn = env.write_txn().unwrap(); for i in 64..128 { - db.put(&mut wtxn, &i.to_string(), "world").unwrap(); + db.put(&wtxn, &i.to_string(), "world").unwrap(); } wtxn.commit().expect_err("cannot commit a transaction that would reach the map size limit"); unsafe { - env.resize(10 * 4096).unwrap(); + env.resize(10 * page_size).unwrap(); } - let mut wtxn = env.write_txn().unwrap(); + let wtxn = env.write_txn().unwrap(); for i in 64..128 { - db.put(&mut wtxn, &i.to_string(), "world").unwrap(); + db.put(&wtxn, &i.to_string(), "world").unwrap(); } wtxn.commit().expect("transaction should commit after resizing the map size"); - assert_eq!(10 * 4096, env.info().map_size); + assert_eq!(10 * page_size, env.info().map_size); } /// Non-regression test for From 277deea887d5b264e1a64fbf7fa430f5361505e6 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Fri, 21 Jul 2023 16:38:25 +0200 Subject: [PATCH 3/6] Fix examples by removing mutable references --- heed/examples/all-types-poly.rs | 22 +-- heed/examples/all-types.rs | 22 +-- heed/examples/clear-database.rs | 10 +- heed/examples/cursor-append.rs | 6 +- heed/examples/multi-env.rs | 8 +- heed/examples/nested.rs | 12 +- heed/src/db/polymorph.rs | 314 +++++++++++++++---------------- heed/src/db/uniform.rs | 324 ++++++++++++++++---------------- heed/src/env.rs | 10 +- heed/src/iterator/mod.rs | 68 +++---- heed/src/lib.rs | 8 +- 11 files changed, 402 insertions(+), 402 deletions(-) diff --git a/heed/examples/all-types-poly.rs b/heed/examples/all-types-poly.rs index 61111c6c..5b6c80b9 100644 --- a/heed/examples/all-types-poly.rs +++ b/heed/examples/all-types-poly.rs @@ -25,7 +25,7 @@ fn main() -> Result<(), Box> { 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?")?; + db.put::, Str>(&wtxn, &[2, 3], "what's up?")?; let ret = db.get::, Str>(&wtxn, &[2, 3])?; println!("{:?}", ret); @@ -35,7 +35,7 @@ fn main() -> Result<(), Box> { let mut wtxn = env.write_txn()?; let db = env.create_poly_database(&mut wtxn, Some("kiki"))?; - db.put::(&mut wtxn, "hello", &[2, 3][..])?; + db.put::(&wtxn, "hello", &[2, 3][..])?; let ret = db.get::(&wtxn, "hello")?; println!("{:?}", ret); @@ -51,13 +51,13 @@ fn main() -> Result<(), Box> { let db = env.create_poly_database(&mut wtxn, Some("serde"))?; let hello = Hello { string: "hi" }; - db.put::>(&mut wtxn, "hello", &hello)?; + db.put::>(&wtxn, "hello", &hello)?; let ret = db.get::>(&wtxn, "hello")?; println!("serde-bincode:\t{:?}", ret); let hello = Hello { string: "hi" }; - db.put::>(&mut wtxn, "hello", &hello)?; + db.put::>(&wtxn, "hello", &hello)?; let ret = db.get::>(&wtxn, "hello")?; println!("serde-json:\t{:?}", ret); @@ -74,7 +74,7 @@ fn main() -> Result<(), Box> { let db = env.create_poly_database(&mut wtxn, Some("nocopy-struct"))?; let zerobytes = ZeroBytes { bytes: [24; 12] }; - db.put::>(&mut wtxn, "zero", &zerobytes)?; + db.put::>(&wtxn, "zero", &zerobytes)?; let ret = db.get::>(&wtxn, "zero")?; @@ -85,7 +85,7 @@ fn main() -> Result<(), Box> { let mut wtxn = env.write_txn()?; let db = env.create_poly_database(&mut wtxn, Some("ignored-data"))?; - db.put::(&mut wtxn, "hello", &())?; + db.put::(&wtxn, "hello", &())?; let ret = db.get::(&wtxn, "hello")?; println!("{:?}", ret); @@ -115,10 +115,10 @@ fn main() -> Result<(), Box> { let db = env.create_poly_database(&mut wtxn, Some("big-endian-iter"))?; - db.put::(&mut wtxn, &0, &())?; - db.put::(&mut wtxn, &68, &())?; - db.put::(&mut wtxn, &35, &())?; - db.put::(&mut wtxn, &42, &())?; + db.put::(&wtxn, &0, &())?; + db.put::(&wtxn, &68, &())?; + db.put::(&wtxn, &35, &())?; + db.put::(&wtxn, &42, &())?; let rets: Result, _> = db.iter::(&wtxn)?.collect(); @@ -132,7 +132,7 @@ fn main() -> Result<(), Box> { // delete a range of key let range = 35..=42; - let deleted: usize = db.delete_range::(&mut wtxn, &range)?; + let deleted: usize = db.delete_range::(&wtxn, &range)?; let rets: Result, _> = db.iter::(&wtxn)?.collect(); diff --git a/heed/examples/all-types.rs b/heed/examples/all-types.rs index 64f885e8..a90dbf52 100644 --- a/heed/examples/all-types.rs +++ b/heed/examples/all-types.rs @@ -25,7 +25,7 @@ fn main() -> Result<(), Box> { let mut wtxn = env.write_txn()?; let db: Database, Str> = env.create_database(&mut wtxn, Some("kikou"))?; - db.put(&mut wtxn, &[2, 3], "what's up?")?; + db.put(&wtxn, &[2, 3], "what's up?")?; let ret: Option<&str> = db.get(&wtxn, &[2, 3])?; println!("{:?}", ret); @@ -35,7 +35,7 @@ fn main() -> Result<(), Box> { let mut wtxn = env.write_txn()?; let db: Database = env.create_database(&mut wtxn, Some("kiki"))?; - db.put(&mut wtxn, "hello", &[2, 3][..])?; + db.put(&wtxn, "hello", &[2, 3][..])?; let ret: Option<&[u8]> = db.get(&wtxn, "hello")?; println!("{:?}", ret); @@ -52,7 +52,7 @@ fn main() -> Result<(), Box> { env.create_database(&mut wtxn, Some("serde-bincode"))?; let hello = Hello { string: "hi" }; - db.put(&mut wtxn, "hello", &hello)?; + db.put(&wtxn, "hello", &hello)?; let ret: Option = db.get(&wtxn, "hello")?; println!("serde-bincode:\t{:?}", ret); @@ -63,7 +63,7 @@ fn main() -> Result<(), Box> { let db: Database> = env.create_database(&mut wtxn, Some("serde-json"))?; let hello = Hello { string: "hi" }; - db.put(&mut wtxn, "hello", &hello)?; + db.put(&wtxn, "hello", &hello)?; let ret: Option = db.get(&wtxn, "hello")?; println!("serde-json:\t{:?}", ret); @@ -82,7 +82,7 @@ fn main() -> Result<(), Box> { env.create_database(&mut wtxn, Some("simple-struct"))?; let zerobytes = ZeroBytes { bytes: [24; 12] }; - db.put(&mut wtxn, "zero", &zerobytes)?; + db.put(&wtxn, "zero", &zerobytes)?; let ret = db.get(&wtxn, "zero")?; @@ -93,7 +93,7 @@ fn main() -> Result<(), Box> { let mut wtxn = env.write_txn()?; let db: Database = env.create_database(&mut wtxn, Some("ignored-data"))?; - db.put(&mut wtxn, "hello", &())?; + db.put(&wtxn, "hello", &())?; let ret: Option<()> = db.get(&wtxn, "hello")?; println!("{:?}", ret); @@ -123,10 +123,10 @@ fn main() -> Result<(), Box> { let db: Database = env.create_database(&mut wtxn, Some("big-endian-iter"))?; - db.put(&mut wtxn, &0, &())?; - db.put(&mut wtxn, &68, &())?; - db.put(&mut wtxn, &35, &())?; - db.put(&mut wtxn, &42, &())?; + db.put(&wtxn, &0, &())?; + db.put(&wtxn, &68, &())?; + db.put(&wtxn, &35, &())?; + db.put(&wtxn, &42, &())?; let rets: Result, _> = db.iter(&wtxn)?.collect(); @@ -140,7 +140,7 @@ fn main() -> Result<(), Box> { // delete a range of key let range = 35..=42; - let deleted: usize = db.delete_range(&mut wtxn, &range)?; + let deleted: usize = db.delete_range(&wtxn, &range)?; let rets: Result, _> = db.iter(&wtxn)?.collect(); diff --git a/heed/examples/clear-database.rs b/heed/examples/clear-database.rs index bc3cea75..e6c6dc97 100644 --- a/heed/examples/clear-database.rs +++ b/heed/examples/clear-database.rs @@ -22,14 +22,14 @@ fn main() -> Result<(), Box> { 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")?; - db.put(&mut wtxn, "I am here too", "for the same purpose")?; + db.put(&wtxn, "I am here", "to test things")?; + db.put(&wtxn, "I am here too", "for the same purpose")?; wtxn.commit()?; - let mut wtxn = env.write_txn()?; - db.clear(&mut wtxn)?; - db.put(&mut wtxn, "And I come back", "to test things")?; + let wtxn = env.write_txn()?; + db.clear(&wtxn)?; + db.put(&wtxn, "And I come back", "to test things")?; let mut iter = db.iter(&wtxn)?; assert_eq!(iter.next().transpose()?, Some(("And I come back", "to test things"))); diff --git a/heed/examples/cursor-append.rs b/heed/examples/cursor-append.rs index 596761f3..34750435 100644 --- a/heed/examples/cursor-append.rs +++ b/heed/examples/cursor-append.rs @@ -23,11 +23,11 @@ fn main() -> Result<(), Box> { 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")?; - first.put(&mut wtxn, "I am here too", "for the same purpose")?; + first.put(&wtxn, "I am here", "to test things")?; + first.put(&wtxn, "I am here too", "for the same purpose")?; // We try to append ordered entries in the second database. - let mut iter = second.iter_mut(&mut wtxn)?; + let mut iter = second.iter_mut(&wtxn)?; unsafe { iter.append("aaaa", "lol")? }; unsafe { iter.append("abcd", "lol")? }; diff --git a/heed/examples/multi-env.rs b/heed/examples/multi-env.rs index 541fce36..94934ef5 100644 --- a/heed/examples/multi-env.rs +++ b/heed/examples/multi-env.rs @@ -28,18 +28,18 @@ fn main() -> Result<(), Box> { env2.create_database(&mut wtxn2, Some("hello"))?; // clear db - db1.clear(&mut wtxn1)?; + db1.clear(&wtxn1)?; wtxn1.commit()?; // clear db - db2.clear(&mut wtxn2)?; + db2.clear(&wtxn2)?; wtxn2.commit()?; // ----- - let mut wtxn1 = env1.write_txn()?; + let wtxn1 = env1.write_txn()?; - db1.put(&mut wtxn1, "what", &[4, 5][..])?; + db1.put(&wtxn1, "what", &[4, 5][..])?; db1.get(&wtxn1, "what")?; wtxn1.commit()?; diff --git a/heed/examples/nested.rs b/heed/examples/nested.rs index cb44ec51..a085f235 100644 --- a/heed/examples/nested.rs +++ b/heed/examples/nested.rs @@ -20,15 +20,15 @@ fn main() -> Result<(), Box> { let db: Database = env.create_database(&mut wtxn, None)?; // clear db - db.clear(&mut wtxn)?; + db.clear(&wtxn)?; wtxn.commit()?; // ----- let mut wtxn = env.write_txn()?; - let mut nwtxn = env.nested_write_txn(&mut wtxn)?; + let nwtxn = env.nested_write_txn(&mut wtxn)?; - db.put(&mut nwtxn, "what", &[4, 5][..])?; + db.put(&nwtxn, "what", &[4, 5][..])?; let ret = db.get(&nwtxn, "what")?; println!("nested(1) \"what\": {:?}", ret); @@ -43,9 +43,9 @@ fn main() -> Result<(), Box> { // also try with multiple levels of nesting let mut nwtxn = env.nested_write_txn(&mut wtxn)?; - let mut nnwtxn = env.nested_write_txn(&mut nwtxn)?; + let nnwtxn = env.nested_write_txn(&mut nwtxn)?; - db.put(&mut nnwtxn, "humm...", &[6, 7][..])?; + db.put(&nnwtxn, "humm...", &[6, 7][..])?; let ret = db.get(&nnwtxn, "humm...")?; println!("nested(2) \"humm...\": {:?}", ret); @@ -56,7 +56,7 @@ fn main() -> Result<(), Box> { let ret = db.get(&wtxn, "humm...")?; println!("parent \"humm...\": {:?}", ret); - db.put(&mut wtxn, "hello", &[2, 3][..])?; + db.put(&wtxn, "hello", &[2, 3][..])?; let ret = db.get(&wtxn, "hello")?; println!("parent \"hello\": {:?}", ret); diff --git a/heed/src/db/polymorph.rs b/heed/src/db/polymorph.rs index 13ca24e9..5f5f75ce 100644 --- a/heed/src/db/polymorph.rs +++ b/heed/src/db/polymorph.rs @@ -34,11 +34,11 @@ use crate::*; /// 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::(&mut wtxn, &0, &())?; -/// db.put::(&mut wtxn, &35, "thirty five")?; -/// db.put::(&mut wtxn, &42, "forty two")?; -/// db.put::(&mut wtxn, &68, &())?; +/// # db.clear(&wtxn)?; +/// db.put::(&wtxn, &0, &())?; +/// db.put::(&wtxn, &35, "thirty five")?; +/// db.put::(&wtxn, &42, "forty two")?; +/// db.put::(&wtxn, &68, &())?; /// /// // you can iterate over database entries in order /// let range = 35..=42; @@ -77,15 +77,15 @@ use crate::*; /// 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::(&mut wtxn, &0, &())?; -/// db.put::(&mut wtxn, &35, "thirty five")?; -/// db.put::(&mut wtxn, &42, "forty two")?; -/// db.put::(&mut wtxn, &68, &())?; +/// # db.clear(&wtxn)?; +/// db.put::(&wtxn, &0, &())?; +/// db.put::(&wtxn, &35, "thirty five")?; +/// db.put::(&wtxn, &42, "forty two")?; +/// db.put::(&wtxn, &68, &())?; /// /// // even delete a range of keys /// let range = 35..=42; -/// let deleted = db.delete_range::(&mut wtxn, &range)?; +/// let deleted = db.delete_range::(&wtxn, &range)?; /// assert_eq!(deleted, 2); /// /// let rets: Result<_, _> = db.iter::(&wtxn)?.collect(); @@ -136,9 +136,9 @@ impl PolyDatabase { /// 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.clear(&wtxn)?; + /// db.put::(&wtxn, "i-am-forty-two", &42)?; + /// db.put::(&wtxn, "i-am-twenty-seven", &27)?; /// /// let ret = db.get::(&wtxn, "i-am-forty-two")?; /// assert_eq!(ret, Some(42)); @@ -206,10 +206,10 @@ impl PolyDatabase { /// let mut wtxn = env.write_txn()?; /// let db = env.create_poly_database(&mut wtxn, Some("get-lt-u32"))?; /// - /// # db.clear(&mut wtxn)?; - /// db.put::(&mut wtxn, &27, &())?; - /// db.put::(&mut wtxn, &42, &())?; - /// db.put::(&mut wtxn, &43, &())?; + /// # db.clear(&wtxn)?; + /// db.put::(&wtxn, &27, &())?; + /// db.put::(&wtxn, &42, &())?; + /// db.put::(&wtxn, &43, &())?; /// /// let ret = db.get_lower_than::(&wtxn, &4404)?; /// assert_eq!(ret, Some((43, ()))); @@ -274,10 +274,10 @@ impl PolyDatabase { /// let mut wtxn = env.write_txn()?; /// let db = env.create_poly_database(&mut wtxn, Some("get-lte-u32"))?; /// - /// # db.clear(&mut wtxn)?; - /// db.put::(&mut wtxn, &27, &())?; - /// db.put::(&mut wtxn, &42, &())?; - /// db.put::(&mut wtxn, &43, &())?; + /// # db.clear(&wtxn)?; + /// db.put::(&wtxn, &27, &())?; + /// db.put::(&wtxn, &42, &())?; + /// db.put::(&wtxn, &43, &())?; /// /// let ret = db.get_lower_than_or_equal_to::(&wtxn, &4404)?; /// assert_eq!(ret, Some((43, ()))); @@ -346,10 +346,10 @@ impl PolyDatabase { /// let mut wtxn = env.write_txn()?; /// let db = env.create_poly_database(&mut wtxn, Some("get-lt-u32"))?; /// - /// # db.clear(&mut wtxn)?; - /// db.put::(&mut wtxn, &27, &())?; - /// db.put::(&mut wtxn, &42, &())?; - /// db.put::(&mut wtxn, &43, &())?; + /// # db.clear(&wtxn)?; + /// db.put::(&wtxn, &27, &())?; + /// db.put::(&wtxn, &42, &())?; + /// db.put::(&wtxn, &43, &())?; /// /// let ret = db.get_greater_than::(&wtxn, &0)?; /// assert_eq!(ret, Some((27, ()))); @@ -417,10 +417,10 @@ impl PolyDatabase { /// let mut wtxn = env.write_txn()?; /// let db = env.create_poly_database(&mut wtxn, Some("get-lt-u32"))?; /// - /// # db.clear(&mut wtxn)?; - /// db.put::(&mut wtxn, &27, &())?; - /// db.put::(&mut wtxn, &42, &())?; - /// db.put::(&mut wtxn, &43, &())?; + /// # db.clear(&wtxn)?; + /// db.put::(&wtxn, &27, &())?; + /// db.put::(&wtxn, &42, &())?; + /// db.put::(&wtxn, &43, &())?; /// /// let ret = db.get_greater_than_or_equal_to::(&wtxn, &0)?; /// assert_eq!(ret, Some((27, ()))); @@ -482,9 +482,9 @@ impl PolyDatabase { /// let mut wtxn = env.write_txn()?; /// let db = env.create_poly_database(&mut wtxn, Some("first-poly-i32"))?; /// - /// # db.clear(&mut wtxn)?; - /// db.put::(&mut wtxn, &42, "i-am-forty-two")?; - /// db.put::(&mut wtxn, &27, "i-am-twenty-seven")?; + /// # db.clear(&wtxn)?; + /// db.put::(&wtxn, &42, "i-am-forty-two")?; + /// db.put::(&wtxn, &27, "i-am-twenty-seven")?; /// /// let ret = db.first::(&wtxn)?; /// assert_eq!(ret, Some((27, "i-am-twenty-seven"))); @@ -535,9 +535,9 @@ impl PolyDatabase { /// let mut wtxn = env.write_txn()?; /// let db = env.create_poly_database(&mut wtxn, Some("last-i32"))?; /// - /// # db.clear(&mut wtxn)?; - /// db.put::(&mut wtxn, &42, "i-am-forty-two")?; - /// db.put::(&mut wtxn, &27, "i-am-twenty-seven")?; + /// # db.clear(&wtxn)?; + /// db.put::(&wtxn, &42, "i-am-forty-two")?; + /// db.put::(&wtxn, &27, "i-am-twenty-seven")?; /// /// let ret = db.last::(&wtxn)?; /// assert_eq!(ret, Some((42, "i-am-forty-two"))); @@ -584,16 +584,16 @@ impl PolyDatabase { /// 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, &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(&wtxn)?; + /// db.put::(&wtxn, &42, "i-am-forty-two")?; + /// db.put::(&wtxn, &27, "i-am-twenty-seven")?; + /// db.put::(&wtxn, &13, "i-am-thirteen")?; + /// db.put::(&wtxn, &521, "i-am-five-hundred-and-twenty-one")?; /// /// let ret = db.len(&wtxn)?; /// assert_eq!(ret, 4); /// - /// db.delete::(&mut wtxn, &27)?; + /// db.delete::(&wtxn, &27)?; /// /// let ret = db.len(&wtxn)?; /// assert_eq!(ret, 3); @@ -638,16 +638,16 @@ impl PolyDatabase { /// 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, &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(&wtxn)?; + /// db.put::(&wtxn, &42, "i-am-forty-two")?; + /// db.put::(&wtxn, &27, "i-am-twenty-seven")?; + /// db.put::(&wtxn, &13, "i-am-thirteen")?; + /// db.put::(&wtxn, &521, "i-am-five-hundred-and-twenty-one")?; /// /// let ret = db.is_empty(&wtxn)?; /// assert_eq!(ret, false); /// - /// db.clear(&mut wtxn)?; + /// db.clear(&wtxn)?; /// /// let ret = db.is_empty(&wtxn)?; /// assert_eq!(ret, true); @@ -686,10 +686,10 @@ impl PolyDatabase { /// 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, &42, "i-am-forty-two")?; - /// db.put::(&mut wtxn, &27, "i-am-twenty-seven")?; - /// db.put::(&mut wtxn, &13, "i-am-thirteen")?; + /// # db.clear(&wtxn)?; + /// db.put::(&wtxn, &42, "i-am-forty-two")?; + /// db.put::(&wtxn, &27, "i-am-twenty-seven")?; + /// db.put::(&wtxn, &13, "i-am-thirteen")?; /// /// let mut iter = db.iter::(&wtxn)?; /// assert_eq!(iter.next().transpose()?, Some((13, "i-am-thirteen"))); @@ -728,12 +728,12 @@ impl PolyDatabase { /// 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, &42, "i-am-forty-two")?; - /// db.put::(&mut wtxn, &27, "i-am-twenty-seven")?; - /// db.put::(&mut wtxn, &13, "i-am-thirteen")?; + /// # db.clear(&wtxn)?; + /// db.put::(&wtxn, &42, "i-am-forty-two")?; + /// db.put::(&wtxn, &27, "i-am-twenty-seven")?; + /// db.put::(&wtxn, &13, "i-am-thirteen")?; /// - /// let mut iter = db.iter_mut::(&mut wtxn)?; + /// let mut iter = db.iter_mut::(&wtxn)?; /// assert_eq!(iter.next().transpose()?, Some((13, "i-am-thirteen"))); /// let ret = unsafe { iter.del_current()? }; /// assert!(ret); @@ -783,10 +783,10 @@ impl PolyDatabase { /// 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, &42, "i-am-forty-two")?; - /// db.put::(&mut wtxn, &27, "i-am-twenty-seven")?; - /// db.put::(&mut wtxn, &13, "i-am-thirteen")?; + /// # db.clear(&wtxn)?; + /// db.put::(&wtxn, &42, "i-am-forty-two")?; + /// db.put::(&wtxn, &27, "i-am-twenty-seven")?; + /// db.put::(&wtxn, &13, "i-am-thirteen")?; /// /// let mut iter = db.rev_iter::(&wtxn)?; /// assert_eq!(iter.next().transpose()?, Some((42, "i-am-forty-two"))); @@ -826,12 +826,12 @@ impl PolyDatabase { /// 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, &42, "i-am-forty-two")?; - /// db.put::(&mut wtxn, &27, "i-am-twenty-seven")?; - /// db.put::(&mut wtxn, &13, "i-am-thirteen")?; + /// # db.clear(&wtxn)?; + /// db.put::(&wtxn, &42, "i-am-forty-two")?; + /// db.put::(&wtxn, &27, "i-am-twenty-seven")?; + /// db.put::(&wtxn, &13, "i-am-thirteen")?; /// - /// let mut iter = db.rev_iter_mut::(&mut wtxn)?; + /// let mut iter = db.rev_iter_mut::(&wtxn)?; /// assert_eq!(iter.next().transpose()?, Some((42, "i-am-forty-two"))); /// let ret = unsafe { iter.del_current()? }; /// assert!(ret); @@ -883,11 +883,11 @@ impl PolyDatabase { /// 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, &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(&wtxn)?; + /// db.put::(&wtxn, &42, "i-am-forty-two")?; + /// db.put::(&wtxn, &27, "i-am-twenty-seven")?; + /// db.put::(&wtxn, &13, "i-am-thirteen")?; + /// db.put::(&wtxn, &521, "i-am-five-hundred-and-twenty-one")?; /// /// let range = 27..=42; /// let mut iter = db.range::(&wtxn, &range)?; @@ -961,14 +961,14 @@ impl PolyDatabase { /// 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, &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(&wtxn)?; + /// db.put::(&wtxn, &42, "i-am-forty-two")?; + /// db.put::(&wtxn, &27, "i-am-twenty-seven")?; + /// db.put::(&wtxn, &13, "i-am-thirteen")?; + /// db.put::(&wtxn, &521, "i-am-five-hundred-and-twenty-one")?; /// /// let range = 27..=42; - /// let mut range = db.range_mut::(&mut wtxn, &range)?; + /// let mut range = db.range_mut::(&wtxn, &range)?; /// assert_eq!(range.next().transpose()?, Some((27, "i-am-twenty-seven"))); /// let ret = unsafe { range.del_current()? }; /// assert!(ret); @@ -1052,11 +1052,11 @@ impl PolyDatabase { /// 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, &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(&wtxn)?; + /// db.put::(&wtxn, &42, "i-am-forty-two")?; + /// db.put::(&wtxn, &27, "i-am-twenty-seven")?; + /// db.put::(&wtxn, &13, "i-am-thirteen")?; + /// db.put::(&wtxn, &521, "i-am-five-hundred-and-twenty-one")?; /// /// let range = 27..=43; /// let mut iter = db.rev_range::(&wtxn, &range)?; @@ -1130,14 +1130,14 @@ impl PolyDatabase { /// 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, &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(&wtxn)?; + /// db.put::(&wtxn, &42, "i-am-forty-two")?; + /// db.put::(&wtxn, &27, "i-am-twenty-seven")?; + /// db.put::(&wtxn, &13, "i-am-thirteen")?; + /// db.put::(&wtxn, &521, "i-am-five-hundred-and-twenty-one")?; /// /// let range = 27..=42; - /// let mut range = db.rev_range_mut::(&mut wtxn, &range)?; + /// let mut range = db.rev_range_mut::(&wtxn, &range)?; /// assert_eq!(range.next().transpose()?, Some((42, "i-am-forty-two"))); /// let ret = unsafe { range.del_current()? }; /// assert!(ret); @@ -1221,14 +1221,14 @@ impl PolyDatabase { /// 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", &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)?; + /// # db.clear(&wtxn)?; + /// db.put::(&wtxn, "i-am-twenty-eight", &28)?; + /// db.put::(&wtxn, "i-am-twenty-seven", &27)?; + /// db.put::(&wtxn, "i-am-twenty-nine", &29)?; + /// db.put::(&wtxn, "i-am-forty-one", &41)?; + /// db.put::(&wtxn, "i-am-forty-two", &42)?; /// - /// let mut iter = db.prefix_iter::(&mut wtxn, "i-am-twenty")?; + /// let mut iter = db.prefix_iter::(&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))); @@ -1277,14 +1277,14 @@ impl PolyDatabase { /// 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", &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)?; + /// # db.clear(&wtxn)?; + /// db.put::(&wtxn, "i-am-twenty-eight", &28)?; + /// db.put::(&wtxn, "i-am-twenty-seven", &27)?; + /// db.put::(&wtxn, "i-am-twenty-nine", &29)?; + /// db.put::(&wtxn, "i-am-forty-one", &41)?; + /// db.put::(&wtxn, "i-am-forty-two", &42)?; /// - /// let mut iter = db.prefix_iter_mut::(&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", 28))); /// let ret = unsafe { iter.del_current()? }; /// assert!(ret); @@ -1346,14 +1346,14 @@ impl PolyDatabase { /// 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", &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)?; + /// # db.clear(&wtxn)?; + /// db.put::(&wtxn, "i-am-twenty-eight", &28)?; + /// db.put::(&wtxn, "i-am-twenty-seven", &27)?; + /// db.put::(&wtxn, "i-am-twenty-nine", &29)?; + /// db.put::(&wtxn, "i-am-forty-one", &41)?; + /// db.put::(&wtxn, "i-am-forty-two", &42)?; /// - /// let mut iter = db.rev_prefix_iter::(&mut wtxn, "i-am-twenty")?; + /// let mut iter = db.rev_prefix_iter::(&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))); @@ -1402,14 +1402,14 @@ impl PolyDatabase { /// 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", &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)?; + /// # db.clear(&wtxn)?; + /// db.put::(&wtxn, "i-am-twenty-eight", &28)?; + /// db.put::(&wtxn, "i-am-twenty-seven", &27)?; + /// db.put::(&wtxn, "i-am-twenty-nine", &29)?; + /// db.put::(&wtxn, "i-am-forty-one", &41)?; + /// db.put::(&wtxn, "i-am-forty-two", &42)?; /// - /// let mut iter = db.rev_prefix_iter_mut::(&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", 27))); /// let ret = unsafe { iter.del_current()? }; /// assert!(ret); @@ -1468,13 +1468,13 @@ impl PolyDatabase { /// 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, &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(&wtxn)?; + /// db.put::(&wtxn, &42, "i-am-forty-two")?; + /// db.put::(&wtxn, &27, "i-am-twenty-seven")?; + /// db.put::(&wtxn, &13, "i-am-thirteen")?; + /// db.put::(&wtxn, &521, "i-am-five-hundred-and-twenty-one")?; /// - /// let ret = db.get::(&mut wtxn, &27)?; + /// let ret = db.get::(&wtxn, &27)?; /// assert_eq!(ret, Some("i-am-twenty-seven")); /// /// wtxn.commit()?; @@ -1528,13 +1528,13 @@ impl PolyDatabase { /// let mut wtxn = env.write_txn()?; /// let db = env.create_poly_database(&mut wtxn, Some("iter-i32"))?; /// - /// # db.clear(&mut wtxn)?; + /// # db.clear(&wtxn)?; /// let value = "I am a long long long value"; - /// db.put_reserved::(&mut wtxn, &42, value.len(), |reserved| { + /// db.put_reserved::(&wtxn, &42, value.len(), |reserved| { /// reserved.write_all(value.as_bytes()) /// })?; /// - /// let ret = db.get::(&mut wtxn, &42)?; + /// let ret = db.get::(&wtxn, &42)?; /// assert_eq!(ret, Some(value)); /// /// wtxn.commit()?; @@ -1595,17 +1595,17 @@ impl PolyDatabase { /// let mut wtxn = env.write_txn()?; /// let db = env.create_poly_database(&mut wtxn, Some("append-i32"))?; /// - /// # db.clear(&mut wtxn)?; - /// db.append::(&mut wtxn, &13, "i-am-thirteen")?; - /// db.append::(&mut wtxn, &27, "i-am-twenty-seven")?; - /// db.append::(&mut wtxn, &42, "i-am-forty-two")?; - /// db.append::(&mut wtxn, &521, "i-am-five-hundred-and-twenty-one")?; + /// # db.clear(&wtxn)?; + /// db.append::(&wtxn, &13, "i-am-thirteen")?; + /// db.append::(&wtxn, &27, "i-am-twenty-seven")?; + /// db.append::(&wtxn, &42, "i-am-forty-two")?; + /// db.append::(&wtxn, &521, "i-am-five-hundred-and-twenty-one")?; /// - /// let ret = db.get::(&mut wtxn, &27)?; + /// let ret = db.get::(&wtxn, &27)?; /// assert_eq!(ret, Some("i-am-twenty-seven")); /// /// // Be wary if you insert at the end unsorted you get the KEYEXIST error. - /// assert!(db.append::(&mut wtxn, &1, "Oh No").is_err()); + /// assert!(db.append::(&wtxn, &1, "Oh No").is_err()); /// /// wtxn.commit()?; /// # Ok(()) } @@ -1659,19 +1659,19 @@ impl PolyDatabase { /// 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, &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(&wtxn)?; + /// db.put::(&wtxn, &42, "i-am-forty-two")?; + /// db.put::(&wtxn, &27, "i-am-twenty-seven")?; + /// db.put::(&wtxn, &13, "i-am-thirteen")?; + /// db.put::(&wtxn, &521, "i-am-five-hundred-and-twenty-one")?; /// - /// let ret = db.delete::(&mut wtxn, &27)?; + /// let ret = db.delete::(&wtxn, &27)?; /// assert_eq!(ret, true); /// - /// let ret = db.get::(&mut wtxn, &27)?; + /// let ret = db.get::(&wtxn, &27)?; /// assert_eq!(ret, None); /// - /// let ret = db.delete::(&mut wtxn, &467)?; + /// let ret = db.delete::(&wtxn, &467)?; /// assert_eq!(ret, false); /// /// wtxn.commit()?; @@ -1725,14 +1725,14 @@ impl PolyDatabase { /// 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, &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(&wtxn)?; + /// db.put::(&wtxn, &42, "i-am-forty-two")?; + /// db.put::(&wtxn, &27, "i-am-twenty-seven")?; + /// db.put::(&wtxn, &13, "i-am-thirteen")?; + /// db.put::(&wtxn, &521, "i-am-five-hundred-and-twenty-one")?; /// /// let range = 27..=42; - /// let ret = db.delete_range::(&mut wtxn, &range)?; + /// let ret = db.delete_range::(&wtxn, &range)?; /// assert_eq!(ret, 2); /// /// let mut iter = db.iter::(&wtxn)?; @@ -1791,13 +1791,13 @@ impl PolyDatabase { /// 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, &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(&wtxn)?; + /// db.put::(&wtxn, &42, "i-am-forty-two")?; + /// db.put::(&wtxn, &27, "i-am-twenty-seven")?; + /// db.put::(&wtxn, &13, "i-am-thirteen")?; + /// db.put::(&wtxn, &521, "i-am-five-hundred-and-twenty-one")?; /// - /// db.clear(&mut wtxn)?; + /// db.clear(&wtxn)?; /// /// let ret = db.is_empty(&wtxn)?; /// assert!(ret); @@ -1840,13 +1840,13 @@ impl PolyDatabase { /// let mut wtxn = env.write_txn()?; /// let db = env.create_poly_database(&mut wtxn, Some("iter-i32"))?; /// - /// # db.clear(&mut wtxn)?; + /// # db.clear(&wtxn)?; /// // We remap the types for ease of use. /// 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")?; + /// db.put(&wtxn, &42, "i-am-forty-two")?; + /// db.put(&wtxn, &27, "i-am-twenty-seven")?; + /// db.put(&wtxn, &13, "i-am-thirteen")?; + /// db.put(&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 03888319..7f10dd6b 100644 --- a/heed/src/db/uniform.rs +++ b/heed/src/db/uniform.rs @@ -31,11 +31,11 @@ use crate::*; /// let mut wtxn = env.write_txn()?; /// let db: Database = env.create_database(&mut wtxn, Some("big-endian-iter"))?; /// -/// # db.clear(&mut wtxn)?; -/// db.put(&mut wtxn, &68, &())?; -/// db.put(&mut wtxn, &35, &())?; -/// db.put(&mut wtxn, &0, &())?; -/// db.put(&mut wtxn, &42, &())?; +/// # db.clear(&wtxn)?; +/// db.put(&wtxn, &68, &())?; +/// db.put(&wtxn, &35, &())?; +/// db.put(&wtxn, &0, &())?; +/// db.put(&wtxn, &42, &())?; /// /// // you can iterate over database entries in order /// let rets: Result<_, _> = db.iter(&wtxn)?.collect(); @@ -78,11 +78,11 @@ use crate::*; /// let mut wtxn = env.write_txn()?; /// let db: Database = env.create_database(&mut wtxn, Some("big-endian-iter"))?; /// -/// # db.clear(&mut wtxn)?; -/// db.put(&mut wtxn, &0, &())?; -/// db.put(&mut wtxn, &68, &())?; -/// db.put(&mut wtxn, &35, &())?; -/// db.put(&mut wtxn, &42, &())?; +/// # db.clear(&wtxn)?; +/// db.put(&wtxn, &0, &())?; +/// db.put(&wtxn, &68, &())?; +/// db.put(&wtxn, &35, &())?; +/// db.put(&wtxn, &42, &())?; /// /// // you can iterate over ranges too!!! /// let range = 35..=42; @@ -98,7 +98,7 @@ use crate::*; /// /// // even delete a range of keys /// let range = 35..=42; -/// let deleted: usize = db.delete_range(&mut wtxn, &range)?; +/// let deleted: usize = db.delete_range(&wtxn, &range)?; /// /// let rets: Result<_, _> = db.iter(&wtxn)?.collect(); /// let rets: Vec<(i64, _)> = rets?; @@ -147,9 +147,9 @@ impl Database { /// 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)?; + /// # db.clear(&wtxn)?; + /// db.put(&wtxn, "i-am-forty-two", &42)?; + /// db.put(&wtxn, "i-am-twenty-seven", &27)?; /// /// let ret = db.get(&wtxn, "i-am-forty-two")?; /// assert_eq!(ret, Some(42)); @@ -194,10 +194,10 @@ impl Database { /// let mut wtxn = env.write_txn()?; /// let db = env.create_database::(&mut wtxn, Some("get-lt-u32"))?; /// - /// # db.clear(&mut wtxn)?; - /// db.put(&mut wtxn, &27, &())?; - /// db.put(&mut wtxn, &42, &())?; - /// db.put(&mut wtxn, &43, &())?; + /// # db.clear(&wtxn)?; + /// db.put(&wtxn, &27, &())?; + /// db.put(&wtxn, &42, &())?; + /// db.put(&wtxn, &43, &())?; /// /// let ret = db.get_lower_than(&wtxn, &4404)?; /// assert_eq!(ret, Some((43, ()))); @@ -249,10 +249,10 @@ impl Database { /// let mut wtxn = env.write_txn()?; /// let db = env.create_database::(&mut wtxn, Some("get-lt-u32"))?; /// - /// # db.clear(&mut wtxn)?; - /// db.put(&mut wtxn, &27, &())?; - /// db.put(&mut wtxn, &42, &())?; - /// db.put(&mut wtxn, &43, &())?; + /// # db.clear(&wtxn)?; + /// db.put(&wtxn, &27, &())?; + /// db.put(&wtxn, &42, &())?; + /// db.put(&wtxn, &43, &())?; /// /// let ret = db.get_lower_than_or_equal_to(&wtxn, &4404)?; /// assert_eq!(ret, Some((43, ()))); @@ -304,10 +304,10 @@ impl Database { /// let mut wtxn = env.write_txn()?; /// let db = env.create_database::(&mut wtxn, Some("get-lt-u32"))?; /// - /// # db.clear(&mut wtxn)?; - /// db.put(&mut wtxn, &27, &())?; - /// db.put(&mut wtxn, &42, &())?; - /// db.put(&mut wtxn, &43, &())?; + /// # db.clear(&wtxn)?; + /// db.put(&wtxn, &27, &())?; + /// db.put(&wtxn, &42, &())?; + /// db.put(&wtxn, &43, &())?; /// /// let ret = db.get_greater_than(&wtxn, &0)?; /// assert_eq!(ret, Some((27, ()))); @@ -359,10 +359,10 @@ impl Database { /// let mut wtxn = env.write_txn()?; /// let db = env.create_database::(&mut wtxn, Some("get-lt-u32"))?; /// - /// # db.clear(&mut wtxn)?; - /// db.put(&mut wtxn, &27, &())?; - /// db.put(&mut wtxn, &42, &())?; - /// db.put(&mut wtxn, &43, &())?; + /// # db.clear(&wtxn)?; + /// db.put(&wtxn, &27, &())?; + /// db.put(&wtxn, &42, &())?; + /// db.put(&wtxn, &43, &())?; /// /// let ret = db.get_greater_than_or_equal_to(&wtxn, &0)?; /// assert_eq!(ret, Some((27, ()))); @@ -413,9 +413,9 @@ impl Database { /// let mut wtxn = env.write_txn()?; /// let db: Database = env.create_database(&mut wtxn, Some("first-i32"))?; /// - /// # db.clear(&mut wtxn)?; - /// db.put(&mut wtxn, &42, "i-am-forty-two")?; - /// db.put(&mut wtxn, &27, "i-am-twenty-seven")?; + /// # db.clear(&wtxn)?; + /// db.put(&wtxn, &42, "i-am-forty-two")?; + /// db.put(&wtxn, &27, "i-am-twenty-seven")?; /// /// let ret = db.first(&wtxn)?; /// assert_eq!(ret, Some((27, "i-am-twenty-seven"))); @@ -456,9 +456,9 @@ impl Database { /// let mut wtxn = env.write_txn()?; /// let db: Database = env.create_database(&mut wtxn, Some("last-i32"))?; /// - /// # db.clear(&mut wtxn)?; - /// db.put(&mut wtxn, &42, "i-am-forty-two")?; - /// db.put(&mut wtxn, &27, "i-am-twenty-seven")?; + /// # db.clear(&wtxn)?; + /// db.put(&wtxn, &42, "i-am-forty-two")?; + /// db.put(&wtxn, &27, "i-am-twenty-seven")?; /// /// let ret = db.last(&wtxn)?; /// assert_eq!(ret, Some((42, "i-am-forty-two"))); @@ -495,16 +495,16 @@ impl Database { /// 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, &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(&wtxn)?; + /// db.put(&wtxn, &42, "i-am-forty-two")?; + /// db.put(&wtxn, &27, "i-am-twenty-seven")?; + /// db.put(&wtxn, &13, "i-am-thirteen")?; + /// db.put(&wtxn, &521, "i-am-five-hundred-and-twenty-one")?; /// /// let ret = db.len(&wtxn)?; /// assert_eq!(ret, 4); /// - /// db.delete(&mut wtxn, &27)?; + /// db.delete(&wtxn, &27)?; /// /// let ret = db.len(&wtxn)?; /// assert_eq!(ret, 3); @@ -537,16 +537,16 @@ impl Database { /// 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, &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(&wtxn)?; + /// db.put(&wtxn, &42, "i-am-forty-two")?; + /// db.put(&wtxn, &27, "i-am-twenty-seven")?; + /// db.put(&wtxn, &13, "i-am-thirteen")?; + /// db.put(&wtxn, &521, "i-am-five-hundred-and-twenty-one")?; /// /// let ret = db.is_empty(&wtxn)?; /// assert_eq!(ret, false); /// - /// db.clear(&mut wtxn)?; + /// db.clear(&wtxn)?; /// /// let ret = db.is_empty(&wtxn)?; /// assert_eq!(ret, true); @@ -579,10 +579,10 @@ impl Database { /// 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, &42, "i-am-forty-two")?; - /// db.put(&mut wtxn, &27, "i-am-twenty-seven")?; - /// db.put(&mut wtxn, &13, "i-am-thirteen")?; + /// # db.clear(&wtxn)?; + /// db.put(&wtxn, &42, "i-am-forty-two")?; + /// db.put(&wtxn, &27, "i-am-twenty-seven")?; + /// db.put(&wtxn, &13, "i-am-thirteen")?; /// /// let mut iter = db.iter(&wtxn)?; /// assert_eq!(iter.next().transpose()?, Some((13, "i-am-thirteen"))); @@ -619,12 +619,12 @@ impl Database { /// 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, &42, "i-am-forty-two")?; - /// db.put(&mut wtxn, &27, "i-am-twenty-seven")?; - /// db.put(&mut wtxn, &13, "i-am-thirteen")?; + /// # db.clear(&wtxn)?; + /// db.put(&wtxn, &42, "i-am-forty-two")?; + /// db.put(&wtxn, &27, "i-am-twenty-seven")?; + /// db.put(&wtxn, &13, "i-am-thirteen")?; /// - /// let mut iter = db.iter_mut(&mut wtxn)?; + /// let mut iter = db.iter_mut(&wtxn)?; /// assert_eq!(iter.next().transpose()?, Some((13, "i-am-thirteen"))); /// let ret = unsafe { iter.del_current()? }; /// assert!(ret); @@ -672,10 +672,10 @@ impl Database { /// 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, &42, "i-am-forty-two")?; - /// db.put(&mut wtxn, &27, "i-am-twenty-seven")?; - /// db.put(&mut wtxn, &13, "i-am-thirteen")?; + /// # db.clear(&wtxn)?; + /// db.put(&wtxn, &42, "i-am-forty-two")?; + /// db.put(&wtxn, &27, "i-am-twenty-seven")?; + /// db.put(&wtxn, &13, "i-am-thirteen")?; /// /// let mut iter = db.rev_iter(&wtxn)?; /// assert_eq!(iter.next().transpose()?, Some((42, "i-am-forty-two"))); @@ -713,12 +713,12 @@ impl Database { /// 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, &42, "i-am-forty-two")?; - /// db.put(&mut wtxn, &27, "i-am-twenty-seven")?; - /// db.put(&mut wtxn, &13, "i-am-thirteen")?; + /// # db.clear(&wtxn)?; + /// db.put(&wtxn, &42, "i-am-forty-two")?; + /// db.put(&wtxn, &27, "i-am-twenty-seven")?; + /// db.put(&wtxn, &13, "i-am-thirteen")?; /// - /// let mut iter = db.rev_iter_mut(&mut wtxn)?; + /// let mut iter = db.rev_iter_mut(&wtxn)?; /// assert_eq!(iter.next().transpose()?, Some((42, "i-am-forty-two"))); /// let ret = unsafe { iter.del_current()? }; /// assert!(ret); @@ -768,11 +768,11 @@ impl Database { /// 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, &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(&wtxn)?; + /// db.put(&wtxn, &42, "i-am-forty-two")?; + /// db.put(&wtxn, &27, "i-am-twenty-seven")?; + /// db.put(&wtxn, &13, "i-am-thirteen")?; + /// db.put(&wtxn, &521, "i-am-five-hundred-and-twenty-one")?; /// /// let range = 27..=42; /// let mut iter = db.range(&wtxn, &range)?; @@ -820,14 +820,14 @@ impl Database { /// 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, &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(&wtxn)?; + /// db.put(&wtxn, &42, "i-am-forty-two")?; + /// db.put(&wtxn, &27, "i-am-twenty-seven")?; + /// db.put(&wtxn, &13, "i-am-thirteen")?; + /// db.put(&wtxn, &521, "i-am-five-hundred-and-twenty-one")?; /// /// let range = 27..=42; - /// let mut range = db.range_mut(&mut wtxn, &range)?; + /// let mut range = db.range_mut(&wtxn, &range)?; /// assert_eq!(range.next().transpose()?, Some((27, "i-am-twenty-seven"))); /// let ret = unsafe { range.del_current()? }; /// assert!(ret); @@ -885,11 +885,11 @@ impl Database { /// 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, &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(&wtxn)?; + /// db.put(&wtxn, &42, "i-am-forty-two")?; + /// db.put(&wtxn, &27, "i-am-twenty-seven")?; + /// db.put(&wtxn, &13, "i-am-thirteen")?; + /// db.put(&wtxn, &521, "i-am-five-hundred-and-twenty-one")?; /// /// let range = 27..=43; /// let mut iter = db.rev_range(&wtxn, &range)?; @@ -937,14 +937,14 @@ impl Database { /// 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, &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(&wtxn)?; + /// db.put(&wtxn, &42, "i-am-forty-two")?; + /// db.put(&wtxn, &27, "i-am-twenty-seven")?; + /// db.put(&wtxn, &13, "i-am-thirteen")?; + /// db.put(&wtxn, &521, "i-am-five-hundred-and-twenty-one")?; /// /// let range = 27..=42; - /// let mut range = db.rev_range_mut(&mut wtxn, &range)?; + /// let mut range = db.rev_range_mut(&wtxn, &range)?; /// assert_eq!(range.next().transpose()?, Some((42, "i-am-forty-two"))); /// let ret = unsafe { range.del_current()? }; /// assert!(ret); @@ -1002,14 +1002,14 @@ impl Database { /// 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", &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)?; + /// # db.clear(&wtxn)?; + /// db.put(&wtxn, "i-am-twenty-eight", &28)?; + /// db.put(&wtxn, "i-am-twenty-seven", &27)?; + /// db.put(&wtxn, "i-am-twenty-nine", &29)?; + /// db.put(&wtxn, "i-am-forty-one", &41)?; + /// db.put(&wtxn, "i-am-forty-two", &42)?; /// - /// let mut iter = db.prefix_iter(&mut wtxn, "i-am-twenty")?; + /// let mut iter = db.prefix_iter(&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))); @@ -1054,14 +1054,14 @@ impl Database { /// 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", &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)?; + /// # db.clear(&wtxn)?; + /// db.put(&wtxn, "i-am-twenty-eight", &28)?; + /// db.put(&wtxn, "i-am-twenty-seven", &27)?; + /// db.put(&wtxn, "i-am-twenty-nine", &29)?; + /// db.put(&wtxn, "i-am-forty-one", &41)?; + /// db.put(&wtxn, "i-am-forty-two", &42)?; /// - /// let mut iter = db.prefix_iter_mut(&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", 28))); /// let ret = unsafe { iter.del_current()? }; /// assert!(ret); @@ -1119,14 +1119,14 @@ impl Database { /// 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", &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)?; + /// # db.clear(&wtxn)?; + /// db.put(&wtxn, "i-am-twenty-eight", &28)?; + /// db.put(&wtxn, "i-am-twenty-seven", &27)?; + /// db.put(&wtxn, "i-am-twenty-nine", &29)?; + /// db.put(&wtxn, "i-am-forty-one", &41)?; + /// db.put(&wtxn, "i-am-forty-two", &42)?; /// - /// let mut iter = db.rev_prefix_iter(&mut wtxn, "i-am-twenty")?; + /// let mut iter = db.rev_prefix_iter(&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))); @@ -1171,14 +1171,14 @@ impl Database { /// 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", &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)?; + /// # db.clear(&wtxn)?; + /// db.put(&wtxn, "i-am-twenty-eight", &28)?; + /// db.put(&wtxn, "i-am-twenty-seven", &27)?; + /// db.put(&wtxn, "i-am-twenty-nine", &29)?; + /// db.put(&wtxn, "i-am-forty-one", &41)?; + /// db.put(&wtxn, "i-am-forty-two", &42)?; /// - /// let mut iter = db.rev_prefix_iter_mut(&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", 27))); /// let ret = unsafe { iter.del_current()? }; /// assert!(ret); @@ -1233,13 +1233,13 @@ impl Database { /// 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, &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(&wtxn)?; + /// db.put(&wtxn, &42, "i-am-forty-two")?; + /// db.put(&wtxn, &27, "i-am-twenty-seven")?; + /// db.put(&wtxn, &13, "i-am-thirteen")?; + /// db.put(&wtxn, &521, "i-am-five-hundred-and-twenty-one")?; /// - /// let ret = db.get(&mut wtxn, &27)?; + /// let ret = db.get(&wtxn, &27)?; /// assert_eq!(ret, Some("i-am-twenty-seven")); /// /// wtxn.commit()?; @@ -1275,13 +1275,13 @@ impl Database { /// let mut wtxn = env.write_txn()?; /// let db = env.create_database::(&mut wtxn, Some("number-string"))?; /// - /// # db.clear(&mut wtxn)?; + /// # db.clear(&wtxn)?; /// let value = "I am a long long long value"; - /// db.put_reserved(&mut wtxn, &42, value.len(), |reserved| { + /// db.put_reserved(&wtxn, &42, value.len(), |reserved| { /// reserved.write_all(value.as_bytes()) /// })?; /// - /// let ret = db.get(&mut wtxn, &42)?; + /// let ret = db.get(&wtxn, &42)?; /// assert_eq!(ret, Some(value)); /// /// wtxn.commit()?; @@ -1325,17 +1325,17 @@ impl Database { /// let mut wtxn = env.write_txn()?; /// let db: Database = env.create_database(&mut wtxn, Some("iter-i32"))?; /// - /// # db.clear(&mut wtxn)?; - /// db.append(&mut wtxn, &13, "i-am-thirteen")?; - /// db.append(&mut wtxn, &27, "i-am-twenty-seven")?; - /// db.append(&mut wtxn, &42, "i-am-forty-two")?; - /// db.append(&mut wtxn, &521, "i-am-five-hundred-and-twenty-one")?; + /// # db.clear(&wtxn)?; + /// db.append(&wtxn, &13, "i-am-thirteen")?; + /// db.append(&wtxn, &27, "i-am-twenty-seven")?; + /// db.append(&wtxn, &42, "i-am-forty-two")?; + /// db.append(&wtxn, &521, "i-am-five-hundred-and-twenty-one")?; /// - /// let ret = db.get(&mut wtxn, &27)?; + /// let ret = db.get(&wtxn, &27)?; /// assert_eq!(ret, Some("i-am-twenty-seven")); /// /// // Be wary if you insert at the end unsorted you get the KEYEXIST error. - /// assert!(db.append(&mut wtxn, &1, "Oh No").is_err()); + /// assert!(db.append(&wtxn, &1, "Oh No").is_err()); /// /// wtxn.commit()?; /// # Ok(()) } @@ -1371,19 +1371,19 @@ impl Database { /// 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, &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(&wtxn)?; + /// db.put(&wtxn, &42, "i-am-forty-two")?; + /// db.put(&wtxn, &27, "i-am-twenty-seven")?; + /// db.put(&wtxn, &13, "i-am-thirteen")?; + /// db.put(&wtxn, &521, "i-am-five-hundred-and-twenty-one")?; /// - /// let ret = db.delete(&mut wtxn, &27)?; + /// let ret = db.delete(&wtxn, &27)?; /// assert_eq!(ret, true); /// - /// let ret = db.get(&mut wtxn, &27)?; + /// let ret = db.get(&wtxn, &27)?; /// assert_eq!(ret, None); /// - /// let ret = db.delete(&mut wtxn, &467)?; + /// let ret = db.delete(&wtxn, &467)?; /// assert_eq!(ret, false); /// /// wtxn.commit()?; @@ -1424,14 +1424,14 @@ impl Database { /// 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, &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(&wtxn)?; + /// db.put(&wtxn, &42, "i-am-forty-two")?; + /// db.put(&wtxn, &27, "i-am-twenty-seven")?; + /// db.put(&wtxn, &13, "i-am-thirteen")?; + /// db.put(&wtxn, &521, "i-am-five-hundred-and-twenty-one")?; /// /// let range = 27..=42; - /// let ret = db.delete_range(&mut wtxn, &range)?; + /// let ret = db.delete_range(&wtxn, &range)?; /// assert_eq!(ret, 2); /// /// @@ -1478,13 +1478,13 @@ impl Database { /// 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, &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(&wtxn)?; + /// db.put(&wtxn, &42, "i-am-forty-two")?; + /// db.put(&wtxn, &27, "i-am-twenty-seven")?; + /// db.put(&wtxn, &13, "i-am-thirteen")?; + /// db.put(&wtxn, &521, "i-am-five-hundred-and-twenty-one")?; /// - /// db.clear(&mut wtxn)?; + /// db.clear(&wtxn)?; /// /// let ret = db.is_empty(&wtxn)?; /// assert!(ret); @@ -1525,13 +1525,13 @@ impl Database { /// let mut wtxn = env.write_txn()?; /// let db: Database = env.create_database(&mut wtxn, Some("iter-i32"))?; /// - /// # db.clear(&mut wtxn)?; + /// # db.clear(&wtxn)?; /// // We remap the types for ease of use. /// 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")?; + /// db.put(&wtxn, &42, "i-am-forty-two")?; + /// db.put(&wtxn, &27, "i-am-twenty-seven")?; + /// db.put(&wtxn, &13, "i-am-thirteen")?; + /// db.put(&wtxn, &521, "i-am-five-hundred-and-twenty-one")?; /// /// wtxn.commit()?; /// # Ok(()) } @@ -1589,11 +1589,11 @@ impl Database { /// 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, &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(&wtxn)?; + /// db.put(&wtxn, &42, "i-am-forty-two")?; + /// db.put(&wtxn, &27, "i-am-twenty-seven")?; + /// db.put(&wtxn, &13, "i-am-thirteen")?; + /// db.put(&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::(&wtxn, &42)?; diff --git a/heed/src/env.rs b/heed/src/env.rs index 0a742618..eacac967 100644 --- a/heed/src/env.rs +++ b/heed/src/env.rs @@ -828,9 +828,9 @@ mod tests { wtxn.commit().unwrap(); // Create an ordered list of keys... - let mut wtxn = env.write_txn().unwrap(); - db.put(&mut wtxn, "hello", "hello").unwrap(); - db.put(&mut wtxn, "world", "world").unwrap(); + let wtxn = env.write_txn().unwrap(); + db.put(&wtxn, "hello", "hello").unwrap(); + db.put(&wtxn, "world", "world").unwrap(); let mut iter = db.iter(&wtxn).unwrap(); assert_eq!(iter.next().transpose().unwrap(), Some(("hello", "hello"))); @@ -1004,8 +1004,8 @@ mod tests { let database0 = env.create_database::(&mut wtxn, Some("shared0")).unwrap(); wtxn.commit().unwrap(); - let mut wtxn = env.write_txn().unwrap(); - database0.put(&mut wtxn, "shared0", expected_data0).unwrap(); + let wtxn = env.write_txn().unwrap(); + database0.put(&wtxn, "shared0", expected_data0).unwrap(); wtxn.commit().unwrap(); // We also really need that no other env reside in memory in other thread doing tests. env.prepare_for_closing().wait(); diff --git a/heed/src/iterator/mod.rs b/heed/src/iterator/mod.rs index 964a0872..4e14faf4 100644 --- a/heed/src/iterator/mod.rs +++ b/heed/src/iterator/mod.rs @@ -42,11 +42,11 @@ mod tests { wtxn.commit().unwrap(); // Create an ordered list of keys... - let mut wtxn = env.write_txn().unwrap(); - db.put(&mut wtxn, &[0, 0, 0, 254, 119, 111, 114, 108, 100], "world").unwrap(); - db.put(&mut wtxn, &[0, 0, 0, 255, 104, 101, 108, 108, 111], "hello").unwrap(); - db.put(&mut wtxn, &[0, 0, 0, 255, 119, 111, 114, 108, 100], "world").unwrap(); - db.put(&mut wtxn, &[0, 0, 1, 0, 119, 111, 114, 108, 100], "world").unwrap(); + let wtxn = env.write_txn().unwrap(); + db.put(&wtxn, &[0, 0, 0, 254, 119, 111, 114, 108, 100], "world").unwrap(); + db.put(&wtxn, &[0, 0, 0, 255, 104, 101, 108, 108, 111], "hello").unwrap(); + db.put(&wtxn, &[0, 0, 0, 255, 119, 111, 114, 108, 100], "world").unwrap(); + db.put(&wtxn, &[0, 0, 1, 0, 119, 111, 114, 108, 100], "world").unwrap(); // Lets check that we can prefix_iter on that sequence with the key "255". let mut iter = db.prefix_iter(&wtxn, &[0, 0, 0, 255]).unwrap(); @@ -84,11 +84,11 @@ mod tests { type BEI32 = I32; // Create an ordered list of keys... - let mut wtxn = env.write_txn().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(); + let wtxn = env.write_txn().unwrap(); + db.put(&wtxn, &1, &()).unwrap(); + db.put(&wtxn, &2, &()).unwrap(); + db.put(&wtxn, &3, &()).unwrap(); + db.put(&wtxn, &4, &()).unwrap(); // Lets check that we properly get the last entry. let iter = db.iter(&wtxn).unwrap(); @@ -118,8 +118,8 @@ mod tests { wtxn.abort(); // Create an ordered list of keys... - let mut wtxn = env.write_txn().unwrap(); - db.put(&mut wtxn, &1, &()).unwrap(); + let wtxn = env.write_txn().unwrap(); + db.put(&wtxn, &1, &()).unwrap(); // Lets check that we properly get the last entry. let iter = db.iter(&wtxn).unwrap(); @@ -152,11 +152,11 @@ mod tests { type BEI32 = I32; // Create an ordered list of keys... - let mut wtxn = env.write_txn().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(); + let wtxn = env.write_txn().unwrap(); + db.put(&wtxn, &1, &()).unwrap(); + db.put(&wtxn, &2, &()).unwrap(); + db.put(&wtxn, &3, &()).unwrap(); + db.put(&wtxn, &4, &()).unwrap(); // Lets check that we properly get the last entry. let iter = db.range(&wtxn, &(..)).unwrap(); @@ -211,8 +211,8 @@ mod tests { wtxn.abort(); // Create an ordered list of keys... - let mut wtxn = env.write_txn().unwrap(); - db.put(&mut wtxn, &1, &()).unwrap(); + let wtxn = env.write_txn().unwrap(); + db.put(&wtxn, &1, &()).unwrap(); // Lets check that we properly get the last entry. let iter = db.range(&wtxn, &(..)).unwrap(); @@ -242,11 +242,11 @@ mod tests { wtxn.commit().unwrap(); // Create an ordered list of keys... - let mut wtxn = env.write_txn().unwrap(); - db.put(&mut wtxn, &[0, 0, 0, 254, 119, 111, 114, 108, 100], &()).unwrap(); - db.put(&mut wtxn, &[0, 0, 0, 255, 104, 101, 108, 108, 111], &()).unwrap(); - db.put(&mut wtxn, &[0, 0, 0, 255, 119, 111, 114, 108, 100], &()).unwrap(); - db.put(&mut wtxn, &[0, 0, 1, 0, 119, 111, 114, 108, 100], &()).unwrap(); + let wtxn = env.write_txn().unwrap(); + db.put(&wtxn, &[0, 0, 0, 254, 119, 111, 114, 108, 100], &()).unwrap(); + db.put(&wtxn, &[0, 0, 0, 255, 104, 101, 108, 108, 111], &()).unwrap(); + db.put(&wtxn, &[0, 0, 0, 255, 119, 111, 114, 108, 100], &()).unwrap(); + db.put(&wtxn, &[0, 0, 1, 0, 119, 111, 114, 108, 100], &()).unwrap(); // Lets check that we properly get the last entry. let iter = db.prefix_iter(&wtxn, &[0, 0, 0]).unwrap(); @@ -317,11 +317,11 @@ mod tests { wtxn.commit().unwrap(); // Create an ordered list of keys... - let mut wtxn = env.write_txn().unwrap(); - db.put(&mut wtxn, &[0, 0, 0, 254, 119, 111, 114, 108, 100], &()).unwrap(); - db.put(&mut wtxn, &[0, 0, 0, 255, 104, 101, 108, 108, 111], &()).unwrap(); - db.put(&mut wtxn, &[0, 0, 0, 255, 119, 111, 114, 108, 100], &()).unwrap(); - db.put(&mut wtxn, &[0, 0, 1, 0, 119, 111, 114, 108, 100], &()).unwrap(); + let wtxn = env.write_txn().unwrap(); + db.put(&wtxn, &[0, 0, 0, 254, 119, 111, 114, 108, 100], &()).unwrap(); + db.put(&wtxn, &[0, 0, 0, 255, 104, 101, 108, 108, 111], &()).unwrap(); + db.put(&wtxn, &[0, 0, 0, 255, 119, 111, 114, 108, 100], &()).unwrap(); + db.put(&wtxn, &[0, 0, 1, 0, 119, 111, 114, 108, 100], &()).unwrap(); // Lets check that we properly get the last entry. let iter = db.rev_prefix_iter(&wtxn, &[0, 0, 0]).unwrap(); @@ -395,11 +395,11 @@ mod tests { type BEI32 = I32; // Create an ordered list of keys... - let mut wtxn = env.write_txn().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(); + let wtxn = env.write_txn().unwrap(); + db.put(&wtxn, &1, &()).unwrap(); + db.put(&wtxn, &2, &()).unwrap(); + db.put(&wtxn, &3, &()).unwrap(); + db.put(&wtxn, &4, &()).unwrap(); // Lets check that we properly get the last entry. let iter = db.rev_range(&wtxn, &(1..=3)).unwrap(); diff --git a/heed/src/lib.rs b/heed/src/lib.rs index 70d4db2a..ee1c534a 100644 --- a/heed/src/lib.rs +++ b/heed/src/lib.rs @@ -29,10 +29,10 @@ //! let db: Database> = env.create_database(&mut wtxn, None)?; //! //! // opening a write transaction -//! db.put(&mut wtxn, "seven", &7)?; -//! db.put(&mut wtxn, "zero", &0)?; -//! db.put(&mut wtxn, "five", &5)?; -//! db.put(&mut wtxn, "three", &3)?; +//! db.put(&wtxn, "seven", &7)?; +//! db.put(&wtxn, "zero", &0)?; +//! db.put(&wtxn, "five", &5)?; +//! db.put(&wtxn, "three", &3)?; //! wtxn.commit()?; //! //! // opening a read transaction From 94a5608031d2155d9303b9a313aa8f9e1972fd0f Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Fri, 21 Jul 2023 17:08:30 +0200 Subject: [PATCH 4/6] Add an example to expose the new possibilities of no more RwTxn --- heed/examples/non-mutable-rwtxn.rs | 97 ++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 heed/examples/non-mutable-rwtxn.rs diff --git a/heed/examples/non-mutable-rwtxn.rs b/heed/examples/non-mutable-rwtxn.rs new file mode 100644 index 00000000..14461ef1 --- /dev/null +++ b/heed/examples/non-mutable-rwtxn.rs @@ -0,0 +1,97 @@ +use std::error::Error; +use std::fs; +use std::path::Path; + +use heed::types::*; +use heed::{Database, EnvOpenOptions}; + +/// This example exposes some of the possibilities using +/// a non-mutable RwTxn to iterate on a database permits. +fn main() -> Result<(), Box> { + let path = Path::new("target").join("heed.mdb"); + + fs::create_dir_all(&path)?; + + let env = EnvOpenOptions::new() + .map_size(10 * 1024 * 1024) // 10MB + .max_dbs(3000) + .open(path)?; + + // here the key will be an str and the data will be a slice of u8 + let mut wtxn = env.write_txn()?; + let one: Database = env.create_database(&mut wtxn, Some("one"))?; + let two: Database = env.create_database(&mut wtxn, Some("two"))?; + + // clear db + one.clear(&wtxn)?; + two.clear(&wtxn)?; + wtxn.commit()?; + + // ----- + + let wtxn = env.write_txn()?; + for number in 0u32..1000 { + let k = number.to_string(); + let v = number.to_be_bytes(); + one.put(&wtxn, &k, &v)?; + } + + for result in one.iter(&wtxn)? { + let (k, v) = result?; + two.put(&wtxn, k, v)?; + } + + for (res1, res2) in one.iter(&wtxn)?.zip(two.iter(&wtxn)?) { + let (k1, v1) = res1?; + let (k2, v2) = res2?; + assert_eq!(k1, k2); + assert_eq!(v1, v2); + } + + wtxn.commit()?; + + // ----- + + let wtxn = env.write_txn()?; + for result in one.iter(&wtxn)? { + let (k, v) = result?; + if k == "10" { + let n: u32 = 11; + one.put(&wtxn, &n.to_string(), &[])?; + } + if k == "11" { + assert!(v.is_empty()); + } + } + + wtxn.commit()?; + + // ----- + + let wtxn = env.write_txn()?; + let n: u32 = 100_000; + one.put(&wtxn, &n.to_string(), &n.to_be_bytes())?; + let v = one.get(&wtxn, &n.to_string())?.unwrap(); + one.put(&wtxn, &n.to_string(), v)?; + + let v = one.get(&wtxn, &n.to_string())?.unwrap(); + assert_eq!(v, n.to_be_bytes()); + + wtxn.commit()?; + + // ----- + + // What happen when we clear the database while iterating on it? + let wtxn = env.write_txn()?; + for result in one.remap_data_type::().iter(&wtxn)? { + let (k, _) = result?; + if k == "10" { + one.clear(&wtxn)?; + } + } + + assert!(one.is_empty(&wtxn)?); + wtxn.commit()?; + + Ok(()) +} From 831f768605650b57e92953199d0f16de8744b938 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Fri, 21 Jul 2023 17:10:50 +0200 Subject: [PATCH 5/6] Make cargo fmt happy --- lmdb-master-sys/tests/lmdb.rs | 6 ++++-- lmdb-master-sys/tests/simple.rs | 17 ++++++++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/lmdb-master-sys/tests/lmdb.rs b/lmdb-master-sys/tests/lmdb.rs index 6628a2d5..f02284b4 100644 --- a/lmdb-master-sys/tests/lmdb.rs +++ b/lmdb-master-sys/tests/lmdb.rs @@ -9,8 +9,10 @@ fn test_lmdb() { lmdb.push("libraries"); lmdb.push("liblmdb"); - let make_cmd = - Command::new("make").current_dir(&lmdb).status().expect("failed to execute process"); + let make_cmd = Command::new("make") + .current_dir(&lmdb) + .status() + .expect("failed to execute process"); assert!(make_cmd.success()); diff --git a/lmdb-master-sys/tests/simple.rs b/lmdb-master-sys/tests/simple.rs index a6ceeea8..b00fbec5 100644 --- a/lmdb-master-sys/tests/simple.rs +++ b/lmdb-master-sys/tests/simple.rs @@ -46,8 +46,14 @@ 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 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 = cstr!("foo").as_ptr() as *mut c_void; let dval = cstr!("bar").as_ptr() as *mut c_void; @@ -59,7 +65,12 @@ fn test_simple(env_path: &str) { E!(mdb_env_open(env, env_path.as_ptr(), 0, 0o664)); E!(mdb_txn_begin(env, ptr::null_mut(), 0, &mut txn)); - E!(mdb_dbi_open(txn, cstr!("subdb").as_ptr(), MDB_CREATE, &mut dbi)); + E!(mdb_dbi_open( + txn, + cstr!("subdb").as_ptr(), + MDB_CREATE, + &mut dbi + )); E!(mdb_txn_commit(txn)); key.mv_size = 3; From 461247fb53f0e57eb593e4746df8ad02e1216b3c Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Sat, 22 Jul 2023 13:59:59 +0200 Subject: [PATCH 6/6] Showcase a new example of adding entries along the way --- heed/examples/non-mutable-rwtxn.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/heed/examples/non-mutable-rwtxn.rs b/heed/examples/non-mutable-rwtxn.rs index 14461ef1..51616d8a 100644 --- a/heed/examples/non-mutable-rwtxn.rs +++ b/heed/examples/non-mutable-rwtxn.rs @@ -21,6 +21,7 @@ fn main() -> Result<(), Box> { let mut wtxn = env.write_txn()?; let one: Database = env.create_database(&mut wtxn, Some("one"))?; let two: Database = env.create_database(&mut wtxn, Some("two"))?; + let numbers: Database = env.create_database(&mut wtxn, Some("numbers"))?; // clear db one.clear(&wtxn)?; @@ -93,5 +94,20 @@ fn main() -> Result<(), Box> { assert!(one.is_empty(&wtxn)?); wtxn.commit()?; + // ----- + + // We can also insert values along the way, while we are iterating + let wtxn = env.write_txn()?; + numbers.put(&wtxn, &0, &())?; + for (result, expected) in numbers.iter(&wtxn)?.zip(0..=u8::MAX) { + let (i, ()) = result?; + assert_eq!(i, expected); + if let Some(next) = i.checked_add(1) { + numbers.put(&wtxn, &next, &())?; + } + } + + wtxn.commit()?; + Ok(()) }