Closed Rudxain closed 7 months ago
I've been considering that, perhaps, this would be more appropriate for something like ranged-ints/deranged
rather than num
If multiple other crates have a shared need for some wrapper, they can collaborate on a common crate, but I definitely don't want to get into implementing all possible number categories here. :)
they can collaborate on a common crate
good point 👍
definitely don't want to get into implementing all possible number categories here. :)
I totally agree! haha. There's literally infinite of them. Even niche ones such as Fib
, and AFAIK, it's extremely rare to find an algorithm that requires Fibonacci numbers (maybe Fib Trees?).
I propose we only focus on simple, everyday stuff, such as Even
& Odd
. There's no need to impl
operator traits, as Deref
can be used to implicitly operate on them as regular ints
Honestly, I'd rather see even the simple stuff developed in their own crate. If it needs small additions in num-integer
(not breaking changes), that might be accommodated, but this isn't a good place for big new experiments.
this isn't a good place for big new experiments
I agree, especially considering rust-num/num#421
Taking inspiration from
NonZero<T>
and Type-driven parsing, what if this crate (or a separate one, for organizing) provided wrappers for specific numeric properties?Strawman examples (not tested as compilable):
New fns could be defined that take advantage of such types. If a fn requires a
Prime
to work properly and safely, it'll no longer have to check primality by itself!The compiler could optimize code using
Even
orOdd
to have the same size and alignment asOption<Even | Odd>
(because LSB is unused).Existing fns could use these types to guarantee stuff such as
If
num
provided such types, there would be less crates implementing their own wrappers, or worse, doing redundant expensive checks:If there was 1: