ctrlc-tiny 0.1.0

A tiny crate for checking if Ctrl-C was pressed, with no threads or handlers to set.
Documentation

ctrlc-tiny

Crates.io Version docs.rs Test

A tiny crate for checking if Ctrl-C was pressed.

No handlers to set. No threads. No AtomicBool.
Just call init_ctrlc() once, then check is_ctrlc_received() in your loop.

✨ Features

  • Signal-safe SIGINT handler
  • No threads, no allocations
  • Zero dependencies
  • Ideal for polling-based CLI tools

🚀 Usage

Add to your Cargo.toml:

ctrlc-tiny = "0.1"

Example:

fn main() -> std::io::Result<()> {
    ctrlc_tiny::init_ctrlc()?;

    loop {
        if ctrlc_tiny::is_ctrlc_received() {
            println!("Ctrl-C detected");
            break;
        }
        // work...
    }

    Ok(())
}

🔍 Why not use ctrlc?

ctrlc provides a flexible way to handle signals using closures and shared state.

It spawns a thread and communicates through channels, which is great for many use cases but may be more than you need if you're just polling for Ctrl-C.

ctrlc-tiny is focused on one job: setting a flag when SIGINT is received. No threads, no handlers, no extra logic.

🔒 Signal Safety

  • Internally uses a volatile sig_atomic_t flag — safe in POSIX signal handlers.
  • No heap, no threads — fully signal-safe by design.

🛠️ Platform Support

  • ✅ Linux
  • ✅ macOS
  • ❌ Windows

📦 License

Licensed under either of:

  • MIT
  • Apache 2.0

See LICENSE-MIT or LICENSE-APACHE.