Type Alias NonZeroI8
type NonZeroI8 = NonZero<i8>
An i8 that is known not to equal zero.
This enables some memory layout optimization.
For example, Option<NonZeroI8> is the same size as i8:
assert_eq!;
Layout
NonZeroI8 is guaranteed to have the same layout and bit validity as i8
with the exception that 0 is not a valid instance.
Option<NonZeroI8> is guaranteed to be compatible with i8,
including in FFI.
Thanks to the null pointer optimization,
NonZeroI8 and Option<NonZeroI8>
are guaranteed to have the same size and alignment:
use NonZeroI8;
assert_eq!;
assert_eq!;
Compile-time creation
Since both [Option::unwrap()] and [Option::expect()] are const, it is possible to
define a new
NonZeroI8
at compile time via:
use NonZeroI8;
const TEN: NonZeroI8 = new.expect;