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
sourceimpl OpenOptions
impl OpenOptions
pub fn new() -> OpenOptions
sourcepub fn truncate(&mut self, truncate: bool) -> &mut OpenOptions
pub fn truncate(&mut self, truncate: bool) -> &mut OpenOptions
Truncate the file on open removing all the persistent data
sourcepub fn create(&mut self, create: bool) -> &mut OpenOptions
pub fn create(&mut self, create: bool) -> &mut OpenOptions
Create a new file if not exists
sourcepub fn create_new(&mut self, create_new: bool) -> &mut OpenOptions
pub fn create_new(&mut self, create_new: bool) -> &mut OpenOptions
Create a new file if exists fail
sourcepub fn prepare_with<F>(&mut self, prepare: F) -> &mut OpenOptions where
F: Fn(&Persy) -> Result<(), Box<dyn Error>> + 'static,
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
sourcepub fn recover_with<F>(&mut self, recover: F) -> &mut OpenOptions where
F: Fn(&Vec<u8>) -> bool + 'static,
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
sourcepub fn config(&mut self, config: Config) -> &mut OpenOptions
pub fn config(&mut self, config: Config) -> &mut OpenOptions
Provide general storage configurations
sourcepub fn recover<P>(&mut self, path: P) -> Result<Recover, PE<OpenError>> where
P: AsRef<Path>,
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
sourcepub fn recover_file(&mut self, file: File) -> Result<Recover, PE<OpenError>>
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
Trait Implementations
sourceimpl Default for OpenOptions
impl Default for OpenOptions
sourcefn default() -> OpenOptions
fn default() -> OpenOptions
Returns the “default value” for a type. Read more
Auto Trait Implementations
impl !RefUnwindSafe for OpenOptions
impl !Send for OpenOptions
impl !Sync for OpenOptions
impl Unpin for OpenOptions
impl !UnwindSafe for OpenOptions
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more