ctrlc

Easy Ctrl-C handler for Rust projects

Latest version: 3.4.7 registry icon
Maintenance score
30
Safety score
100
Popularity score
81
Check your open source dependency risks. Get immediate insight about security, stability and licensing risks.
Security
  Vulnerabilities
Version Suggest Low Medium High Critical
3.4.7 0 0 0 0 0
3.4.6 0 0 0 0 0
3.4.5 0 0 0 0 0
3.4.4 0 0 0 0 0
3.4.3 0 0 0 0 0
3.4.2 0 0 0 0 0
3.4.1 0 0 0 0 0
3.4.0 0 0 0 0 0
3.3.1 0 0 0 0 0
3.3.0 0 0 0 0 0
3.2.5 0 0 0 0 0
3.2.4 0 0 0 0 0
3.2.3 0 0 0 0 0
3.2.2 0 0 0 0 0
3.2.1 0 0 0 0 0
3.2.0 0 0 0 0 0
3.1.10 0 0 0 0 0
3.1.9 0 0 0 0 0
3.1.8 0 0 0 0 0
3.1.7 0 0 0 0 0
3.1.6 0 0 0 0 0
3.1.5 0 0 0 0 0
3.1.4 0 0 0 0 0
3.1.3 0 0 0 0 0
3.1.2 0 0 0 0 0
3.1.1 0 0 0 0 0
3.1.0 0 0 0 0 0
3.0.3 0 0 0 0 0
3.0.2 0 0 0 0 0
3.0.1 0 0 0 0 0
3.0.0 0 0 0 0 0
2.0.1 0 0 0 0 0
2.0.0 0 0 0 0 0
1.1.1 0 0 0 0 0
1.1.0 0 0 0 0 0
1.0.1 0 0 0 0 0
1.0.0 0 0 0 0 0
0.1.2 0 0 0 0 0
0.1.1 0 0 0 0 0
0.1.0 0 0 0 0 0

Stability
Latest release:

3.4.7 - This version may not be safe as it has not been updated for a long time. Find out if your coding project uses this component and get notified of any reported security vulnerabilities with Meterian-X Open Source Security Platform

Licensing

Maintain your licence declarations and avoid unwanted licences to protect your IP the way you intended.

Apache-2.0   -   Apache License 2.0

Not a wildcard

Not proprietary

OSI Compliant


MIT   -   MIT License

Not a wildcard

Not proprietary

OSI Compliant



CtrlC

A simple easy to use wrapper around Ctrl-C signal.

Documentation

Example usage

In cargo.toml:

[dependencies]
ctrlc = "3.4"

then, in main.rs

use std::sync::mpsc::channel;
use ctrlc;

fn main() {
    let (tx, rx) = channel();
    
    ctrlc::set_handler(move || tx.send(()).expect("Could not send signal on channel."))
        .expect("Error setting Ctrl-C handler");
    
    println!("Waiting for Ctrl-C...");
    rx.recv().expect("Could not receive from channel.");
    println!("Got it! Exiting..."); 
}

Try the example yourself

cargo build --examples && target/debug/examples/readme_example

Handling SIGTERM and SIGHUP

Add CtrlC to Cargo.toml using termination feature and CtrlC will handle SIGINT, SIGTERM and SIGHUP.

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you shall be dual licensed as above, without any additional terms or conditions.

Similar crates

There are alternatives that give you more control over the different signals and/or add async support.