What it does
NonZero<T> stabilized with Rust 1.79.0. This allows NonZeroI32 to be written as NonZero<i32>.
Advantage
- More readable.
- Reduce imports.
- Can specify aliases for primitive integer types (e.g.,
NonZero<c_int>).
Drawbacks
MSRV is 1.79.0.
Example
let x = NonZeroI32::new(42).unwrap();
Could be written as:
let x = NonZero::<i32>::new(42).unwrap();