Expand description
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.
Structs§
- Signal
Stream - An asynchronous stream of Signals generated by trap_stream.
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
bodyis 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. - trap_
stream - 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.