filelock-rs 0.1.0-beta.2

Minimal Rust library that provides functionality for managing PID files and file locks.
Documentation
  • Coverage
  • 100%
    14 out of 14 items documented3 out of 11 items with examples
  • Size
  • Source code size: 32.15 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.1 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 12s Average build duration of successful builds.
  • all releases: 12s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • rsmicro/filelock-rs
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • vincenzopalazzo

filelock-rs

Crates.io Documentation

filelock-rs is a Rust library that provides functionality for managing PID files and file locks.

Features

  • Pid: The pid module provides functionality for creating, reading, and managing PID files.
  • FdLock: The fdlock module provides a trait FdLock that extends the AsRawFd trait, allowing file locks to be placed on file descriptors.

Installation

Add this to your Cargo.toml:

[dependencies]
filelock-rs = "0.1.0"

Usage

use filelock-rs_rs::pid::Pid;
use filelock-rs_rs::fdlock::FdLock;

fn main() {
    // Store the file in the struct of the process
    // because the pid stop to exist when this Pid instance
    // is dropped.
    let pid_file = Pid::new("/var/run", "my_app").expect("Failed to create PID file");

    let file = std::fs::File::new("/tmp/file.txt").unwrap();
    // Lock the file exclusively
    file.lock_exclusive().expect("Failed to lock PID file");

    // Perform some operations...

    // Unlock the file
    file.unlock().expect("Failed to unlock PID file");
}

License

Copyright 2023 Vincenzo Palazzo <vincenzopalazzodev@gmail.com>. See LICENSE file.