#singleton #instance #detail

single-instance

A rust library for single instance application

8 releases

Uses old Rust 2015

0.3.3 Dec 16, 2021
0.3.2 Sep 22, 2021
0.3.1 Feb 14, 2021
0.2.0 Feb 13, 2021
0.1.0 Jan 30, 2018

#9 in #singleton

Download history 2657/week @ 2024-12-21 2759/week @ 2024-12-28 3722/week @ 2025-01-04 3054/week @ 2025-01-11 2850/week @ 2025-01-18 2922/week @ 2025-01-25 3307/week @ 2025-02-01 3969/week @ 2025-02-08 8230/week @ 2025-02-15 6100/week @ 2025-02-22 5503/week @ 2025-03-01 7298/week @ 2025-03-08 4717/week @ 2025-03-15 5395/week @ 2025-03-22 5038/week @ 2025-03-29 4394/week @ 2025-04-05

20,946 downloads per month
Used in 22 crates (21 directly)

MIT license

9KB
156 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
~59K SLoC