rust-num / num-traits

Numeric traits for generic mathematics in Rust
Apache License 2.0
694 stars 131 forks source link

Add `BitOrAssign` etc. to `PrimInt` #304

Closed Enyium closed 8 months ago

Enyium commented 8 months ago

PrimInt already has bounds for BitOr etc. Is it an oversight that the ...Assign variants are missing?

Currently, I can do:

container = container | t;

...but not:

container |= t;

...when t has a PrimInt bound and container is initialized with T::zero().

cuviper commented 8 months ago

I think it's because Primint is simply older -- all of the OpAssign traits were "only" stabilized in Rust 1.8.0, and it's a breaking change to add more requirements to PrimInt since it's not a sealed trait. But you could make your own extended trait that requires more, something like:

trait MyPrimInt: PrimInt + BitOrAssign + ... {}
impl<T: PrimInt + BitOrAssign + ...> MyPrimInt for T {}
Enyium commented 8 months ago

Don't you gather breaking changes to perform them one day?

cuviper commented 8 months ago

In theory, yes, but in practice I'm afraid that a breaking semver bump will fracture the ecosystem, since these traits are often used in others' public APIs.

Enyium commented 8 months ago

Hm, I guess I'll close this then.