Crate fd_lock

Source
Expand description

Advisory reader-writer locks for files.

§Notes on Advisory Locks

“advisory locks” are locks which programs must opt-in to adhere to. This means that they can be used to coordinate file access, but not prevent access. Use this to coordinate file access between multiple instances of the same program. But do not use this to prevent actors from accessing or modifying files.

§Example

use std::io::prelude::*;
use std::fs::File;
use fd_lock::RwLock;

// Lock a file and write to it.
let mut f = RwLock::new(File::open("foo.txt")?);
write!(f.write()?, "chashu cat")?;

// A lock can also be held across multiple operations.
let mut f = f.write()?;
write!(f, "nori cat")?;
write!(f, "bird!")?;

Structs§

RwLock
Advisory reader-writer lock for files.
RwLockReadGuard
RAII structure used to release the shared read access of a lock when dropped.
RwLockWriteGuard
RAII structure used to release the exclusive write access of a lock when dropped.