Struct persy::OpenOptions[][src]

pub struct OpenOptions { /* fields omitted */ }
Expand description

Options, flags, configs which can be used to configure how a persy database is opened.

use persy::{OpenOptions, Persy, PersyId, ValueMode};

// This function will only be called on database creation
fn init(persy: &Persy) -> Result<(), Box<dyn std::error::Error>> {
    let mut tx = persy.begin()?;

    tx.create_segment("data")?;
    tx.create_index::<u64, PersyId>("index", ValueMode::Replace)?;

    let prepared = tx.prepare()?;
    prepared.commit()?;

    println!("Segment and Index successfully created");
    Ok(())
}

let persy = OpenOptions::new().create(true).prepare_with(init).open("target/persy.db")?;

Implementations

Truncate the file on open removing all the persistent data

Create a new file if not exists

Create a new file if exists fail

Provide a function for initialize the storage in case did not existed

Provide a function for check if a transaction must be committed or rollback in case of recover from crash

Provide general storage configurations

Open a file to a recover structure to list pending transactions and select witch commit and rollback

Open a file to a recover structure to list pending transactions and select witch commit and rollback

Open a file from the given path with the current options

Create a persy instance backed by a Vec<u8> with no persistence

Example

use persy::{OpenOptions, Persy, PersyId, ValueMode};


let persy = OpenOptions::new().memory()?;

Trait Implementations

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.