filelock

Crates.iofilelock
lib.rsfilelock
version0.4.2
created_at2021-09-06 15:35:28.421504+00
updated_at2025-12-04 12:08:06.819245+00
descriptionCross-platform file locking library for Rust
homepage
repositoryhttps://github.com/aisk/filelock
max_upload_size
id447575
size21,870
AN Long (aisk)

documentation

README

filelock

Rust

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

Image by Homutan, source: https://www.pixiv.net/artworks/128080460

Installation

$ cargo add filelock

Usage

use filelock;

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:

use filelock;

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(())
}

Documentation

See https://docs.rs/filelock/latest/filelock/.

License

Filelock is distributed by a MIT license.

Commit count: 0

cargo fmt