#macro #unreachable #xkcd

xkcd_unreachable

受 https://xkcd.com/2200/ 启发的 Rust 宏 xkcd_unreachable!()

2 个版本

0.1.1 2020年3月16日
0.1.0 2020年3月16日

#1371 in Rust 模式

每月下载 39
nenv 中使用

MIT 许可证

7KB
58

xkcd_unreachable

xkcd 2200 启发的 Rust 宏 xkcd_unreachable!()

示例

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")
    }
}

达到时的输出

⚠ 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/>

更多信息,请参阅 文档

xkcd 2200

无运行时依赖