# Elevate \`NonZero\*\` types to true primitive integer types?

**URL:** <https://internals.rust-lang.org/t/elevate-nonzero-types-to-true-primitive-integer-types/18040>\
**Category:** language design\
**Created:** [December 27, 2022, 7:12pm UTC](https://internals.rust-lang.org/t/elevate-nonzero-types-to-true-primitive-integer-types/18040 "2022-12-27T19:12:46Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![scottmcm](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/scottmcm/32/2355_2.png) [@scottmcm](https://internals.rust-lang.org/u/scottmcm)\
**Post date:** [December 27, 2022, 9:15pm UTC](https://internals.rust-lang.org/t/elevate-nonzero-types-to-true-primitive-integer-types/18040/2 "2022-12-27T21:15:20Z")

</div>

My meta-thought here is that it all sounds ok-ish, but that I wish every one of the things would go just a tiny bit futher.

For example, rather than having some traits return the non-zero type and some return the could-be-zero type, just have a ranged type so it always have the correct size (like I describe in [Non-negative integer types - #20 by scottmcm](https://internals.rust-lang.org/t/non-negative-integer-types/17796/20)).

And rather than adding a suffix for non-zero, extend `{integer}` to be something usable by more types -- so `NonZeroU32`, but also `num::BitUInt` and such. Using some sort of "const trait" support, so that the compiler can run the parsing as a const, so if it panics it's a compilation error.

> [@dead-claudia](#):
>
> NonZeroU32::new(123).unwrap()

While it's even longer, I'll toss in `const { NonZeroU32::new(123).unwrap() }` -- that way you'll get a compilation error if you passed in 0, so it's guaranteed as fast as the `unsafe` version while still being safe.

> [@dead-claudia](#):
>
> In reality, all of the integer operations could technically be implemented for the non-zero unsigned types as follows

This sounds like a partial version of what I described

---

_[View the full topic](https://internals.rust-lang.org/t/elevate-nonzero-types-to-true-primitive-integer-types/18040)._
