Struct cdb::CDBWriter

source ·
pub struct CDBWriter { /* private fields */ }
Expand description

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.

Example

use cdb::CDBWriter;

fn main() -> std::io::Result<()> {
    let mut cdb = CDBWriter::create("temporary.cdb")?;
    cdb.add(b"one", b"Hello")?;
    cdb.finish()?;
    Ok(())
}

Implementations

Safely create a new CDB file.

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

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

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.

Add a record to the CDB file.

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.

Trait Implementations

Executes the destructor for this 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

Returns the argument unchanged.

Calls U::from(self).

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

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.