never-say-never 6.6.666

The never type (the true one!) in stable Rust.
Documentation
  • Coverage
  • 100%
    2 out of 2 items documented1 out of 1 items with examples
  • Size
  • Source code size: 22.61 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 505.54 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • danielhenrymantilla/never-say-never.rs
    40 1 1
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • danielhenrymantilla

::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,
};