Crates.io | never-say-never |
lib.rs | never-say-never |
version | 6.6.666 |
source | src |
created_at | 2022-01-19 13:47:40.487343 |
updated_at | 2022-01-19 14:10:42.226503 |
description | The never type (the true one!) in stable Rust. |
homepage | |
repository | https://github.com/danielhenrymantilla/never-say-never.rs |
max_upload_size | |
id | 516746 |
size | 23,338 |
::never-say-never
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 {}
.
::core::convert::Infallible
is a sad instance of the
latter.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,
};