fd_lock/lib.rs
1//! Advisory reader-writer locks for files.
2//!
3//! # Notes on Advisory Locks
4//!
5//! "advisory locks" are locks which programs must opt-in to adhere to. This
6//! means that they can be used to coordinate file access, but not prevent
7//! access. Use this to coordinate file access between multiple instances of the
8//! same program. But do not use this to prevent actors from accessing or
9//! modifying files.
10//!
11//! # Example
12//!
13//! ```no_run
14//! # use std::io;
15//! use std::io::prelude::*;
16//! use std::fs::File;
17//! use fd_lock::RwLock;
18//!
19//! # fn main() -> io::Result<()> {
20//! // Lock a file and write to it.
21//! let mut f = RwLock::new(File::open("foo.txt")?);
22//! write!(f.write()?, "chashu cat")?;
23//!
24//! // A lock can also be held across multiple operations.
25//! let mut f = f.write()?;
26//! write!(f, "nori cat")?;
27//! write!(f, "bird!")?;
28//! # Ok(()) }
29//! ```
30
31#![forbid(future_incompatible)]
32#![deny(missing_debug_implementations, nonstandard_style)]
33#![cfg_attr(doc, warn(missing_docs, rustdoc::missing_doc_code_examples))]
34
35mod read_guard;
36mod rw_lock;
37mod write_guard;
38
39pub(crate) mod sys;
40
41pub use read_guard::RwLockReadGuard;
42pub use rw_lock::RwLock;
43pub use write_guard::RwLockWriteGuard;