yoshuawuyts/fd-lock

Advisory cross-platform file locks using file descriptors

Rust

89

91 commits

updated Jun 17, 2026

See the code

README

fd-lock

crates.io version downloads docs.rs docs

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.

Examples

Basic usage

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!")?;

Installation

$ cargo add fd-lock

Safety

This crate uses unsafe on Windows to interface with windows-sys. All invariants have been carefully checked, and are manually enforced.

Contributing

Want to join us? Check out our "Contributing" guide and take a look at some of these issues:

References

License

MIT OR Apache-2.0

Project health

Overall

3.1/10

Maintained

0/10

Code review

3/10
OpenSSF Scorecard

crates.io

Latest release

4.0.4 · Mar 10, 2025

Releases this year

0

Significant stargazers

Mathias Buus

6,379 followers · starred Jun 2019

Ivan 🦀

699 followers · starred Apr 2026

kpcyrd

1,025 followers · starred Jul 2023

Martin Liška

162 followers · starred Jun 2025

yoshuawuyts/fd-lock

Advisory cross-platform file locks using file descriptors

Rust

89

91 commits

updated Jun 17, 2026

See the code

README

fd-lock

crates.io version downloads docs.rs docs

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.

Examples

Basic usage

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!")?;

Installation

$ cargo add fd-lock

Safety

This crate uses unsafe on Windows to interface with windows-sys. All invariants have been carefully checked, and are manually enforced.

Contributing

Want to join us? Check out our "Contributing" guide and take a look at some of these issues:

References

License

MIT OR Apache-2.0

Project health

Overall

3.1/10

Maintained

0/10

Code review

3/10
OpenSSF Scorecard

crates.io

Latest release

4.0.4 · Mar 10, 2025

Releases this year

0

Significant stargazers

Mathias Buus

6,379 followers · starred Jun 2019

Ivan 🦀

699 followers · starred Apr 2026

kpcyrd

1,025 followers · starred Jul 2023

Martin Liška

162 followers · starred Jun 2025