Skip to content

Commit

Permalink
Merge pull request #246 from hinto-janai/open
Browse files Browse the repository at this point in the history
Set `EnvOpenOptions::open()` to `unsafe`
  • Loading branch information
Kerollmops authored Mar 4, 2024
2 parents 1372597 + cda37c6 commit 029a25b
Show file tree
Hide file tree
Showing 13 changed files with 360 additions and 222 deletions.
10 changes: 6 additions & 4 deletions heed/examples/all-types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ fn main() -> Result<(), Box<dyn Error>> {

fs::create_dir_all(&path)?;

let env = EnvOpenOptions::new()
.map_size(10 * 1024 * 1024) // 10MB
.max_dbs(3000)
.open(path)?;
let env = unsafe {
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()?;
Expand Down
10 changes: 6 additions & 4 deletions heed/examples/clear-database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ fn main() -> Result<(), Box<dyn Error>> {
let _ = fs::remove_dir_all(&env_path);

fs::create_dir_all(&env_path)?;
let env = EnvOpenOptions::new()
.map_size(10 * 1024 * 1024) // 10MB
.max_dbs(3)
.open(env_path)?;
let env = unsafe {
EnvOpenOptions::new()
.map_size(10 * 1024 * 1024) // 10MB
.max_dbs(3)
.open(env_path)?
};

let mut wtxn = env.write_txn()?;
let db: Database<Str, Str> = env.create_database(&mut wtxn, Some("first"))?;
Expand Down
10 changes: 6 additions & 4 deletions heed/examples/cursor-append.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ fn main() -> Result<(), Box<dyn Error>> {
let _ = fs::remove_dir_all(&env_path);

fs::create_dir_all(&env_path)?;
let env = EnvOpenOptions::new()
.map_size(10 * 1024 * 1024) // 10MB
.max_dbs(3)
.open(env_path)?;
let env = unsafe {
EnvOpenOptions::new()
.map_size(10 * 1024 * 1024) // 10MB
.max_dbs(3)
.open(env_path)?
};

let mut wtxn = env.write_txn()?;
let first: Database<Str, Str> = env.create_database(&mut wtxn, Some("first"))?;
Expand Down
10 changes: 6 additions & 4 deletions heed/examples/custom-comparator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ fn main() -> Result<(), Box<dyn Error>> {
let _ = fs::remove_dir_all(&env_path);

fs::create_dir_all(&env_path)?;
let env = EnvOpenOptions::new()
.map_size(10 * 1024 * 1024) // 10MB
.max_dbs(3)
.open(env_path)?;
let env = unsafe {
EnvOpenOptions::new()
.map_size(10 * 1024 * 1024) // 10MB
.max_dbs(3)
.open(env_path)?
};

let mut wtxn = env.write_txn()?;
let db = env
Expand Down
20 changes: 12 additions & 8 deletions heed/examples/multi-env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,20 @@ fn main() -> Result<(), Box<dyn Error>> {
let env2_path = Path::new("target").join("env2.mdb");

fs::create_dir_all(&env1_path)?;
let env1 = EnvOpenOptions::new()
.map_size(10 * 1024 * 1024) // 10MB
.max_dbs(3000)
.open(env1_path)?;
let env1 = unsafe {
EnvOpenOptions::new()
.map_size(10 * 1024 * 1024) // 10MB
.max_dbs(3000)
.open(env1_path)?
};

fs::create_dir_all(&env2_path)?;
let env2 = EnvOpenOptions::new()
.map_size(10 * 1024 * 1024) // 10MB
.max_dbs(3000)
.open(env2_path)?;
let env2 = unsafe {
EnvOpenOptions::new()
.map_size(10 * 1024 * 1024) // 10MB
.max_dbs(3000)
.open(env2_path)?
};

let mut wtxn1 = env1.write_txn()?;
let mut wtxn2 = env2.write_txn()?;
Expand Down
10 changes: 6 additions & 4 deletions heed/examples/nested.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ fn main() -> Result<(), Box<dyn Error>> {

fs::create_dir_all(&path)?;

let env = EnvOpenOptions::new()
.map_size(10 * 1024 * 1024) // 10MB
.max_dbs(3000)
.open(path)?;
let env = unsafe {
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()?;
Expand Down
10 changes: 6 additions & 4 deletions heed/examples/rmp-serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ fn main() -> Result<(), Box<dyn Error>> {

fs::create_dir_all(&path)?;

let env = EnvOpenOptions::new()
.map_size(10 * 1024 * 1024) // 10MB
.max_dbs(3000)
.open(path)?;
let env = unsafe {
EnvOpenOptions::new()
.map_size(10 * 1024 * 1024) // 10MB
.max_dbs(3000)
.open(path)?
};

// you can specify that a database will support some typed key/data
// serde types are also supported!!!
Expand Down
Loading

0 comments on commit 029a25b

Please sign in to comment.