Currently, there is no way to obtain a NonZero* value without introducing unsafe codes or unwrap() calls, providing these constants can make it easier to use these types. For example:
use std::num::NonZeroU64;
fn foo(x: u64) -> NonZeroU64 {
x.checked_add(1).and_then(NonZeroU64::new).unwrap_or(NonZeroU64::MAX)
}
Currently, there is no way to obtain a
NonZero*value without introducing unsafe codes orunwrap()calls, providing these constants can make it easier to use these types. For example: