https://github.com/aisk/rust-filelock
https://github.com/aisk/rust-filelock
rust
Last synced: 18 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/aisk/rust-filelock
- Owner: aisk
- License: mit
- Created: 2021-09-06T15:36:27.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2026-02-13T16:34:13.000Z (3 months ago)
- Last Synced: 2026-02-14T00:42:18.339Z (3 months ago)
- Topics: rust
- Language: Rust
- Homepage: https://crates.io/crates/filelock
- Size: 24.4 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# filelock
[](https://github.com/aisk/filelock/actions/workflows/ci.yml)
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
```sh
$ cargo add filelock
```
## Usage
```rust
use filelock;
fn main() -> Result<(), Box> {
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:
```rust
use filelock;
fn main() -> Result<(), Box> {
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](https://github.com/aisk/filelock/tree/master/LICENSE).