[][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.


wintrap::trap(&[wintrap::Signal::CtrlC, wintrap::Signal::CloseWindow], |signal| {
    // handle signal here
    println!("Caught a signal: {:?}", signal);
}, || {
    // do work
    println!("Doing work");


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.



An asynchronous stream of Signals generated by trap_stream.



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.


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



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.


Traps one or more Signals into a SignalStream. During the execution of the body function, all signals specified will be yielded as items in the stream.