Struct cdb::CDBWriter [] [src]

pub struct CDBWriter {
    // some fields omitted
}

A CDB file writer which handles atomic updating.

Using this type, a CDB file is safely written by first creating a temporary file, building the CDB structure into that temporary file, and finally renaming that temporary file over the final file name. If the temporary file is not properly finished (ie due to an error), the temporary file is deleted when this writer is dropped.

Methods

impl CDBWriter

fn create<P: AsRef<Path> + ToString>(filename: P) -> Result<CDBWriter>

Safely create a new CDB file.

The suffix for the temporary file defaults to ".tmp".

fn with_suffix<P: AsRef<Path> + ToString>(filename: P, suffix: &str) -> Result<CDBWriter>

Safely create a new CDB file, using a specific suffix for the temporary file.

fn with_filenames<P: AsRef<Path> + ToString, Q: AsRef<Path> + ToString>(filename: P, tmpname: Q) -> Result<CDBWriter>

Safely create a new CDB file, using two specific file names.

Note that the temporary file name must be on the same filesystem as the destination, or else the final rename will fail.

fn add(&mut self, key: &[u8], data: &[u8]) -> Result<()>

Add a record to the CDB file.

fn set_permissions(&mut self, perm: Permissions) -> Result<()>

Set permissions on the temporary file.

This must be done before the file is finished, as the temporary file will no longer exist at that point.

fn finish(&mut self) -> Result<()>

Trait Implementations

impl Drop for CDBWriter

fn drop(&mut self)