Sometimes I want to implement a trait for multiple unsigned types.
Examples from the standard library (if it was designed from scratch):
std::ops::Shl<Rhs>only really makes sense for unsigned
Iterator::take(n)would make sense for any unsigned n, not just
usize, for instance you may want to have 64-bit
non a 32-bit platform so
usizeis not sufficient
Changing the standard library like this wouldn't be backwards compatible, but similar considerations apply to other code elsewhere.
One problem with this is that if an integer literal is valid for multiple types but not for
i32, then there is no default. So if
Iterator::take supported multiple unsigned types, you wouldn't be able to just say
A solution to this is to have second fallback type: if
i32 doesn't work, but
u32 works, use
This seems backwards compatible to me, since it only affects scenarios that currently don't compile.