Skip to content

Commit

Permalink
Introduce a test to check that transvasing entries works
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerollmops committed Mar 5, 2025
1 parent a75a8c0 commit dec6a50
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions heed/src/cookbook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//!
//! - [Decode Values on Demand](#decode-values-on-demand)
//! - [Listing and Opening the Named Databases](#listing-and-opening-the-named-databases)
//! - [Moving entries from one database to another](#moving-entries-from-one-database-to-another)
//! - [Create Custom and Prefix Codecs](#create-custom-and-prefix-codecs)
//! - [Change the Environment Size Dynamically](#change-the-environment-size-dynamically)
//! - [Advanced Multithreaded Access of Entries](#advanced-multithreaded-access-of-entries)
Expand Down Expand Up @@ -129,6 +130,73 @@
//! }
//! ```
//!
//! # Moving entries from one database to another
//!
//! TBD
//!
//! ```rust,compile_fail
//! # use std::error::Error;
//! # use heed::types::*;
//! # use heed::{Database, EnvOpenOptions};
//! # fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
//! # let path = tempfile::tempdir()?;
//! # let env = unsafe {
//! # EnvOpenOptions::new()
//! # .map_size(1024 * 1024 * 100) // 100 MiB
//! # .open(&path)?
//! # };
//! let mut wtxn = env.write_txn()?;
//! # let database1: Database<Str, Str> = env.create_database(&mut wtxn, Some("database1"))?;
//! # let database2: Database<Str, Str> = env.create_database(&mut wtxn, Some("database2"))?;
//! # for i in 0..10 {
//! # let key = format!("key{}", i);
//! # let value = format!("value{}", i);
//! # database1.put(&mut wtxn, &key, &value)?;
//! # }
//! for result in database1.iter(&wtxn)? {
//! let (k, v) = result?;
//! // compilation error: cannot use &mut and & of RwTxn simultaneously
//! database2.put(&mut wtxn, k, v)?;
//! }
//! # wtxn.commit()?;
//! # Ok(())
//! # }
//! ```
//!
//! TBD we use an iter_mut + as_wtxn and owned strings. Explain why this is necessary.
//!
//! ```
//! # use std::error::Error;
//! # use heed::types::*;
//! # use heed::{Database, EnvOpenOptions};
//! # fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
//! # let path = tempfile::tempdir()?;
//! # let env = unsafe {
//! # EnvOpenOptions::new()
//! # .max_dbs(10)
//! # .map_size(1024 * 1024 * 100) // 100 MiB
//! # .open(&path)?
//! # };
//! let mut wtxn = env.write_txn()?;
//! # let database1: Database<Str, Str> = env.create_database(&mut wtxn, Some("database1"))?;
//! # let database2: Database<Str, Str> = env.create_database(&mut wtxn, Some("database2"))?;
//! # for i in 0..10 {
//! # let key = format!("key{}", i);
//! # let value = format!("value{}", i);
//! # database1.put(&mut wtxn, &key, &value)?;
//! # }
//! let mut iter = database1.iter_mut(&mut wtxn)?;
//! while let Some((k, v)) = iter.next().transpose()? {
//! let ck = k.to_owned();
//! let cv = v.to_owned();
//! database2.put(iter.as_wtxn(), &ck, &cv)?;
//! }
//! # drop(iter);
//! # wtxn.commit()?;
//! # Ok(())
//! # }
//! ```
//!
//! # Create Custom and Prefix Codecs
//!
//! With heed you can store any kind of data and serialize it the way you want.
Expand Down

0 comments on commit dec6a50

Please sign in to comment.