num-traits icon indicating copy to clipboard operation
num-traits copied to clipboard

Consider a trait for NonZero* integers

Open raphaelcohn opened this issue 4 years ago • 2 comments

I wanted a trait to identify NonZero* integers (eg NonZeroU32) and my first thought was this crate. I didn't seem a trait for them.

In my very specific use case, I actually need a trait that relates the zero and non-zero unsigned integers. Of course, I can trivially create one, but this seems more useful in this pseudo-standard Rust crate.

For example:-

trait NonZeroInteger
{
}

impl NonZeroInteger for NonZeroU32
{
}

and possibly

trait Integer
{
    type NonZeroInteger: NonZeroInteger
}

I suppose there's a debate to be had as to whether NonNull would also implement such a trait. I'd argue not - rather there should be a super trait of NonZero and a sub trait of NonZeroInteger - but that's quite arguable either way.

raphaelcohn avatar May 19 '21 08:05 raphaelcohn

See #85

geeknoid avatar Aug 08 '24 02:08 geeknoid

Also std::num::NonZero provides a generic solution

tarcieri avatar Aug 08 '24 02:08 tarcieri