6 releases
0.3.1 | May 26, 2021 |
---|---|
0.3.0 | Jan 29, 2019 |
0.2.1 | Jan 27, 2019 |
0.1.1 | Jan 18, 2019 |
#717 in Operating systems
43 downloads per month
Used in battery-savior
27KB
586 lines
wintrap-rs
The wintrap
crate allows a Windows process to trap one or more abstracted
"signals", running an asynchronous callback function whenever they are caught
while active.
Examples
wintrap::trap(vec![wintrap::Signal::CtrlC, wintrap::Signal::CloseWindow], |signal| {
// handle signal here
println!("Caught a signal: {:?}", signal);
}, || {
// do work
println!("Doing work");
}).unwrap();
Caveats
Please note that it is not possible to correctly trap Ctrl-C signals when
running programs via cargo run
. You will have to run them directly via the
target directory after building.
lib.rs
:
The wintrap
crate allows a Windows process to trap one or more abstracted
"signals", running a callback function in a dedicated thread whenever they
are caught while active.
Examples
wintrap::trap(&[wintrap::Signal::CtrlC, wintrap::Signal::CloseWindow], |signal| {
// handle signal here
println!("Caught a signal: {:?}", signal);
}, || {
// do work
println!("Doing work");
}).unwrap();
Caveats
Please note that it is not possible to correctly trap Ctrl-C signals when
running programs via cargo run
. You will have to run them directly via
the target directory after building.
Dependencies
~400–640KB