Advisory cross-platform file locks using file descriptors.
Note that advisory lock compliance is opt-in, and can freely be ignored by other parties. This means this crate should not be relied on for security, but solely used to coordinate file access.
use fd_lock::FdLock; // Lock a file and write to it. let mut f = FdLock::new(tempfile()?); f.try_lock()?.write_all(b"chashu cat")?; // Locks can also be held for extended durations. let mut f = f.try_lock()?; f.write_all(b"nori cat")?; f.write_all(b"bird!")?;
A file descriptor lock.
A guard that unlocks the file descriptor when it goes out of scope.