Function ctrlc::set_handler[][src]

pub fn set_handler<F>(user_handler: F) -> Result<(), Error> where
    F: FnMut() + 'static + Send

Register signal handler for Ctrl-C.

Starts a new dedicated signal handling thread. Should only be called once, typically at the start of your program.

Example

ctrlc::set_handler(|| println!("Hello world!")).expect("Error setting Ctrl-C handler");

Warning

On Unix, any existing SIGINT, SIGTERM(if termination feature is enabled) or SA_SIGINFO posix signal handlers will be overwritten. On Windows, multiple handler routines are allowed, but they are called on a last-registered, first-called basis until the signal is handled.

On Unix, signal dispositions and signal handlers are inherited by child processes created via fork(2) on, but not by child processes created via execve(2). Signal handlers are not inherited on Windows.

Errors

Will return an error if another ctrlc::set_handler() handler exists or if a system error occurred while setting the handler.

Panics

Any panic in the handler will not be caught and will cause the signal handler thread to stop.