All Projects → io12 → Xkcd Unreachable Rs

io12 / Xkcd Unreachable Rs

Licence: mit
A Rust macro xkcd_unreachable!() inspired by https://xkcd.com/2200/

Programming Languages

rust
11053 projects
macro
33 projects

xkcd_unreachable

A Rust macro xkcd_unreachable!() inspired by xkcd 2200

Example

use xkcd_unreachable::xkcd_unreachable;

fn foo(x: Option<i32>) {
    match x {
        Some(n) if n >= 0 => println!("Some(Non-negative)"),
        Some(n) if n <  0 => println!("Some(Negative)"),
        Some(_)           => xkcd_unreachable!(),
        None              => println!("None")
    }
}

Output if reached

⚠ ERROR

If you're seeing this, the code is in what
I thought was an unreachable state.

I could give you advice for what to do.
But honestly, why should you trust me?
I clearly screwed this up. I'm writing a
message that should never appear, yet
I know it will probably appear someday.

On a deep level, I know I'm not
up to this task. I'm so sorry.

<https://xkcd.com/2200/>

For more information, see the documentation.

xkcd 2200

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].