pub fn set_handler(
signal_type: SignalType,
handler: SignalHandler,
) -> Result<(), SetHandlerError>Available on Windows and crate feature
signals only.Expand description
Installs the specified handler for the specified signal.
ยงExample
use interprocess::os::windows::signal::{self, SignalType, SignalHandler};
let handler = unsafe {
// Since signal handlers are restricted to a specific set of C functions, creating a
// handler from an arbitrary function is unsafe because it might call a function
// outside the list, and there's no real way to know that at compile time with the
// current version of Rust. Since we're only using the write() system call here, this
// is safe.
SignalHandler::from_fn(|| {
println!("You pressed Ctrl-C!");
})
};
// Install our handler for the KeyboardInterrupt signal type.
signal::set_handler(SignalType::KeyboardInterrupt, handler)?;