#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

#1458 in Rust patterns

Download history 9950/week @ 2024-01-05 11308/week @ 2024-01-12 15600/week @ 2024-01-19 14337/week @ 2024-01-26 7476/week @ 2024-02-02 12058/week @ 2024-02-09 12578/week @ 2024-02-16 11490/week @ 2024-02-23 12389/week @ 2024-03-01 15300/week @ 2024-03-08 14337/week @ 2024-03-15 14101/week @ 2024-03-22 11458/week @ 2024-03-29 14480/week @ 2024-04-05 15423/week @ 2024-04-12 14799/week @ 2024-04-19

57,952 downloads per month
Used in 24 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