11 releases

0.2.1 Dec 20, 2021
0.2.0 Oct 25, 2021
0.1.8 Sep 25, 2021
0.1.7 Aug 10, 2021
0.1.4 Jan 1, 2020

#62 in Filesystem

Download history 83560/week @ 2023-12-14 40900/week @ 2023-12-21 44733/week @ 2023-12-28 80367/week @ 2024-01-04 81374/week @ 2024-01-11 93996/week @ 2024-01-18 83440/week @ 2024-01-25 77707/week @ 2024-02-01 92379/week @ 2024-02-08 79310/week @ 2024-02-15 94458/week @ 2024-02-22 102980/week @ 2024-02-29 92395/week @ 2024-03-07 96731/week @ 2024-03-14 95097/week @ 2024-03-21 89769/week @ 2024-03-28

395,218 downloads per month
Used in 276 crates (36 directly)

MIT license

50KB
1K SLoC

fslock

API to use files as a lock. Supports non-std crates by disabling feature std.

Types

Currently, only one type is provided: LockFile. It does not destroy the file after closed and behaviour on locking different file handles owned by the same process is different between Unix and Windows, unless you activate the multilock feature, which enables the open_excl method that locks files per file descriptor/handle on all platforms.

Example

use fslock::LockFile;
fn main() -> Result<(), fslock::Error> {

    let mut file = LockFile::open("mylock")?;
    file.lock()?;
    do_stuff();
    file.unlock()?;

    Ok(())
}

Docs on Master

https://brunoczim.github.io/fslock/fslock


lib.rs:

API to use files as a lock. Supports non-std crates by disabling feature std.

Types

Currently, only one type is provided: LockFile. It does not destroy the file after closed. Locks are per-handle and not by per-process in any platform. On Unix, however, under fork file descriptors might be duplicated sharing the same lock, but fork is usually unsafe in Rust.

Example

use fslock::LockFile;
fn main() -> Result<(), fslock::Error> {

    let mut file = LockFile::open("testfiles/mylock.lock")?;
    file.lock()?;
    do_stuff();
    file.unlock()?;

    Ok(())
}

Dependencies

~215KB