Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/rust/rust_kvs/examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ use std::collections::HashMap;
use tempfile::tempdir;

fn main() -> Result<(), ErrorCode> {
// Temporary directory.
// Temporary directory and common backend.
let dir = tempdir()?;
let dir_string = dir.path().to_string_lossy().to_string();
let dir_path = dir.path().to_path_buf();
let backend = Box::new(JsonBackendBuilder::new().working_dir(dir_path).build());

// Instance ID for KVS object instances.
let instance_id = InstanceId(0);
Expand All @@ -20,7 +21,7 @@ fn main() -> Result<(), ErrorCode> {
// `kvs_load` is explicitly set to `KvsLoad::Optional`, but this is the default value.
// KVS files are not required.
let builder = KvsBuilder::new(instance_id)
.dir(dir_string.clone())
.backend(backend.clone())
.kvs_load(KvsLoad::Optional);
let kvs = builder.build()?;

Expand Down Expand Up @@ -65,7 +66,7 @@ fn main() -> Result<(), ErrorCode> {
// Build KVS instance for given instance ID and temporary directory.
// `kvs_load` is set to `KvsLoad::Required` - KVS files must already exist from previous KVS instance.
let builder = KvsBuilder::new(instance_id)
.dir(dir_string)
.backend(backend)
.kvs_load(KvsLoad::Required);
let kvs = builder.build()?;

Expand Down
7 changes: 4 additions & 3 deletions src/rust/rust_kvs/examples/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ fn create_defaults_file(dir_path: PathBuf, instance_id: InstanceId) -> Result<()
}

fn main() -> Result<(), ErrorCode> {
// Temporary directory.
// Temporary directory and common backend.
let dir = tempdir()?;
let dir_string = dir.path().to_string_lossy().to_string();
let dir_path = dir.path().to_path_buf();
let backend = Box::new(JsonBackendBuilder::new().working_dir(dir_path).build());

// Instance ID for KVS object instances.
let instance_id = InstanceId(0);
Expand All @@ -44,7 +45,7 @@ fn main() -> Result<(), ErrorCode> {
// Build KVS instance for given instance ID and temporary directory.
// `defaults` is set to `KvsDefaults::Required` - defaults are required.
let builder = KvsBuilder::new(instance_id)
.dir(dir_string)
.backend(backend.clone())
.defaults(KvsDefaults::Required);
let kvs = builder.build()?;

Expand Down
9 changes: 5 additions & 4 deletions src/rust/rust_kvs/examples/snapshots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ use rust_kvs::prelude::*;
use tempfile::tempdir;

fn main() -> Result<(), ErrorCode> {
// Temporary directory.
// Temporary directory and common backend.
let dir = tempdir()?;
let dir_string = dir.path().to_string_lossy().to_string();
let dir_path = dir.path().to_path_buf();
let backend = Box::new(JsonBackendBuilder::new().working_dir(dir_path).build());

// Instance ID for KVS object instances.
let instance_id = InstanceId(0);
Expand All @@ -17,7 +18,7 @@ fn main() -> Result<(), ErrorCode> {
println!("-> `snapshot_count` and `snapshot_max_count` usage");

// Build KVS instance for given instance ID and temporary directory.
let builder = KvsBuilder::new(instance_id).dir(dir_string.clone());
let builder = KvsBuilder::new(instance_id).backend(backend.clone());
let kvs = builder.build()?;

let max_count = kvs.snapshot_max_count() as u32;
Expand All @@ -38,7 +39,7 @@ fn main() -> Result<(), ErrorCode> {
println!("-> `snapshot_restore` usage");

// Build KVS instance for given instance ID and temporary directory.
let builder = KvsBuilder::new(instance_id).dir(dir_string.clone());
let builder = KvsBuilder::new(instance_id).backend(backend.clone());
let kvs = builder.build()?;

let max_count = kvs.snapshot_max_count() as u32;
Expand Down
Loading
Loading