#say #ever #never #flying-pigs

never-say-never

The never type (the true one!) in stable Rust

2 stable releases

6.6.666 Jan 19, 2022

#1639 in Rust patterns

Download history 15911/week @ 2024-03-13 14815/week @ 2024-03-20 10306/week @ 2024-03-27 14805/week @ 2024-04-03 14003/week @ 2024-04-10 18013/week @ 2024-04-17 17546/week @ 2024-04-24 16157/week @ 2024-05-01 15124/week @ 2024-05-08 19859/week @ 2024-05-15 19213/week @ 2024-05-22 21399/week @ 2024-05-29 17782/week @ 2024-06-05 16971/week @ 2024-06-12 18949/week @ 2024-06-19 21832/week @ 2024-06-26

79,113 downloads per month
Used in 25 crates (6 directly)

Zlib OR MIT OR Apache-2.0

8KB

::never-say-never

Repository Latest version Documentation MSRV unsafe forbidden License CI

The ! type. In stable Rust. Since 1.14.0.

Better than an enum Never {} definition would be, since an instance of type ! automagically coerces to any type, whereas an instance of enum EmptyEnum {} needs an explicit match it {}.

That is, the following fails to compile:

let x: u32 = match <u32 as TryFrom<u8>>::try_from(42) {
    | Ok(it) => it,
    | Err(unreachable) => unreachable, // Error, expected `u32`, found `Infallible`
};

but the following doesn't!

use ::never_say_never::Never;

let x: u32 = match Ok::<_, Never>(42) {
    | Ok(it) => it,
    | Err(unreachable) => unreachable,
};

No runtime deps