#single #singleton #instance #applications #file #running #error

bin+lib wei-single

A rust library for single instance application

2 releases

Uses old Rust 2015

0.3.6 Mar 17, 2024
0.3.5 Jan 13, 2024

#17 in #singleton

Download history 2/week @ 2024-01-11 10/week @ 2024-02-22 7/week @ 2024-02-29 128/week @ 2024-03-14 16/week @ 2024-03-21 27/week @ 2024-03-28 14/week @ 2024-04-04

63 downloads per month
Used in wei-scheduler

MIT license

12KB
196 lines

single-instance

Crates.io Build Status

single-instance provides a single API to check if there are any other running instance.

Detail

On windows, init SingleInstance will create a mutex named by given &str then check error code by calling GetLastError. On linux init will bind abstract unix domain socket with given name . On macos, init will create or open a file which path is given &str, then call flock to apply an advisory lock on the open file.

[dependencies]
single-instance = "0.3"

Examples

extern crate single_instance;

use single_instance::SingleInstance;

fn main() {
    {
        let instance_a = SingleInstance::new("whatever").unwrap();
        assert!(instance_a.is_single());
        let instance_b = SingleInstance::new("whatever").unwrap();
        assert!(!instance_b.is_single());
    }
    let instance_c = SingleInstance::new("whatever").unwrap();
    assert!(instance_c.is_single());
}

Dependencies

~3MB
~61K SLoC