Struct persy::OpenOptions

source ·
pub struct OpenOptions { /* private fields */ }
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§

source§

impl OpenOptions

source

pub fn new() -> OpenOptions

source

pub fn truncate(&mut self, truncate: bool) -> &mut OpenOptions

Truncate the file on open removing all the persistent data

source

pub fn create(&mut self, create: bool) -> &mut OpenOptions

Create a new file if not exists

source

pub fn create_new(&mut self, create_new: bool) -> &mut OpenOptions

Create a new file if exists fail

source

pub fn prepare_with<F>(&mut self, prepare: F) -> &mut OpenOptions
where F: Fn(&Persy) -> Result<(), Box<dyn Error>> + 'static,

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

source

pub fn recover_with<F>(&mut self, recover: F) -> &mut OpenOptions
where F: Fn(&Vec<u8>) -> bool + 'static,

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

source

pub fn config(&mut self, config: Config) -> &mut OpenOptions

Provide general storage configurations

source

pub fn recover<P>(&mut self, path: P) -> Result<Recover, PE<OpenError>>
where P: AsRef<Path>,

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

source

pub fn recover_file(&mut self, file: File) -> Result<Recover, PE<OpenError>>

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

source

pub fn open<P>(&mut self, path: P) -> Result<Persy, PE<OpenError>>
where P: AsRef<Path>,

Open a file from the given path with the current options

source

pub fn memory(&mut self) -> Result<Persy, PE<OpenMemoryError>>

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§

source§

impl Default for OpenOptions

source§

fn default() -> OpenOptions

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

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V