Need help with rust-ctrlc?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

Detegr
269 Stars 50 Forks Other 147 Commits 9 Opened issues

Description

Easy Ctrl-C handler for Rust projects

Services available

!
?

Need anything else?

Contributors list

# 88,052
Rust
Git
filesys...
regex
84 commits
# 566,908
Rust
4 commits
# 11,400
C#
c-sharp
.NET
rabbitm...
4 commits
# 113,261
Rust
Homebre...
typeset...
opam
3 commits
# 34,967
Symfony
q
mesh-ne...
rust-la...
2 commits
# 3,359
Rust
convers...
Objecti...
test-fr...
2 commits
# 41,512
Rust
Django
google-...
google-...
2 commits
# 2,702
Ethereu...
swarm
circlec...
Go
2 commits
# 34,982
Rust
Shell
rust-la...
rpc-fra...
2 commits
# 201,153
HTML
JavaScr...
d3
svg
1 commit
# 11,654
Rust
vulkan
parity
node
1 commit
# 316,142
Shell
React
Rust
terrain
1 commit
# 45,737
Rust
Shell
winapi
ffi
1 commit
# 43,559
Rust
ffi-bin...
rust-la...
gzip
1 commit
# 614,498
notepad
Shell
daemon
TypeScr...
1 commit
# 72,312
test-fr...
templat...
cpp11
paramet...
1 commit
# 41,225
basic-a...
node
readlin...
R
1 commit
# 156,888
Clojure
Zsh
Clojure...
interce...
1 commit
# 315,608
Haskell
Shell
agda
brick
1 commit
# 27,866
Rust
rust-la...
trait
viml
1 commit

CtrlC

Build Status Build status

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

Documentation

Example usage

use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;

fn main() { let running = Arc::new(AtomicBool::new(true)); let r = running.clone(); ctrlc::set_handler(move || { r.store(false, Ordering::SeqCst); }).expect("Error setting Ctrl-C handler"); println!("Waiting for Ctrl-C..."); while running.load(Ordering::SeqCst) {} println!("Got it! Exiting..."); }

Try the example yourself

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

Handling SIGTERM

Add CtrlC to Cargo.toml using

termination
feature and CtrlC will handle both SIGINT and SIGTERM.
[dependencies]
ctrlc = { version = "3.0", features = ["termination"] }

License

Licensed under either of * Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0) * MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT) at your option.

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.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.