[][src]Crate wintrap

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(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.

Enums

Error

An error that may potentially be generated by trap. These errors will rarely ever be produced, and you can unwrap Results safely in most cases.

Signal

Represents one of several abstracted "signals" available to Windows processes. A number of these signals may be associated with a single trap call.

Functions

trap

Associates one or more Signals to an callback function to be executed in a dedicated thread while body is executing. A caveat of its usage is that only one thread is ever able to trap signals throughout the entire execution of your program. You are free to nest traps freely, however, only the innermost signal handlers will be executed.