Skip to main content

Module atomic

Module atomic 

Source
Expand description

RAII-based atomic file guard for safe marketplace mutations.

AtomicGuard creates a timestamped backup of a file before mutation begins. If the operation succeeds, call AtomicGuard::commit to remove the backup. If the guard is dropped without committing (e.g., due to an early return or error propagation), the original file is automatically restored from the backup.

§Examples

use souk_core::ops::AtomicGuard;
use std::path::Path;

fn update_marketplace(path: &Path) -> Result<(), souk_core::SoukError> {
    let guard = AtomicGuard::new(path)?;

    // ... modify the file at `path` ...

    // Success: remove the backup.
    guard.commit()?;
    Ok(())
}

Structs§

AtomicGuard
An RAII guard that backs up a file before mutation and restores it on drop unless explicitly committed.