Advisory cross-platform file locks using file descriptors. Adapted from [mafintosh/fd-lock].
Note that advisory lock compliance is opt-in, and can freely be ignored by other parties. This means this crate should never be used for security purposes, but solely to coordinate file access.
Basic usage ```rust use fd_lock::RwLock; use tempfile::tempfile; use std::io::prelude::*; use std::fs::File;
fn main() -> Result<(), failure::Error> { // Lock a file and write to it. let mut f = RwLock::new(tempfile()?); f.write()?.write_all(b"chashu cat")?;
// A lock can also be held across multiple operations.
let mut f = f.write()?;
f.write_all(b"nori cat")?;
f.write_all(b"bird!")?;
Ok(())
} ```
sh
$ cargo add fd-lock
This crate uses unsafe to interface with libc and winapi. All invariants
have been carefully checked, and are manually enforced.
Want to join us? Check out our "Contributing" guide and take a look at some of these issues:
MIT OR Apache-2.0