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
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
pub fn prepare_with<F>(&mut self, prepare: F) -> &mut OpenOptions
Provide a function for initialize the storage in case did not existed
sourcepub fn recover_with<F>(&mut self, recover: F) -> &mut OpenOptions
pub fn recover_with<F>(&mut self, recover: F) -> &mut OpenOptions
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>>
pub fn recover<P>(&mut self, path: P) -> Result<Recover, PE<OpenError>>
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§
source§impl Default for OpenOptions
impl Default for OpenOptions
source§fn default() -> OpenOptions
fn default() -> OpenOptions
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for OpenOptions
impl !RefUnwindSafe for OpenOptions
impl !Send for OpenOptions
impl !Sync for OpenOptions
impl Unpin for OpenOptions
impl !UnwindSafe for OpenOptions
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more