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

#41 in Concurrency

Download history 16042/week @ 2022-08-08 16876/week @ 2022-08-15 17881/week @ 2022-08-22 21830/week @ 2022-08-29 18672/week @ 2022-09-05 18877/week @ 2022-09-12 21087/week @ 2022-09-19 19888/week @ 2022-09-26 18988/week @ 2022-10-03 18601/week @ 2022-10-10 19309/week @ 2022-10-17 22785/week @ 2022-10-24 21903/week @ 2022-10-31 20629/week @ 2022-11-07 20542/week @ 2022-11-14 18061/week @ 2022-11-21

81,940 downloads per month
Used in 123 crates (18 directly)

MIT license

49KB
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(())
}
# fn do_stuff() {
#    // doing stuff here.
# }

Dependencies

~35KB