Crate filelock

Crate filelock 

Source
Expand description

Simple filelock library for rust, using flock on Unix-like systems and LockFileEx on Windows under the hood.

§Usage

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut lock = filelock::new("myfile.lock");
    let _guard = lock.lock()?;

    // Perform critical operations

    // Lock is automatically released when _guard goes out of scope
    Ok(())
}

For manual control:

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut lock = filelock::new("myfile.lock");
    let guard = lock.lock()?;

    // Perform critical operations

    // Manually unlock with error handling
    guard.unlock()?;

    Ok(())
}

Structs§

FileLock
FileLockGuard
A guard that holds a file lock and automatically releases it when dropped.

Functions§

new
Creates a new FileLock instance.