I want to write generic functions of the form
fn my_function<T: num::Unsigned>(T: number) -> T
in order to use them for all unsigned integer types, so u8-u128.
However, often I want to do something like
let n = number + 1;
or
let mut n = number;
number -= 1;
in the function body. Now, everytime I use something like that, Rust tells me that the std::ops::SubAssign-trait, the std::cmp::PartialOrd-trait, etc. is not implemented for T.
Is there an easy way to specify that my number is only one of the types u8-u128 and hence enjoys all of those traits? And why isn't this clear to the Rust compiler, i.e. what would be an example for an Unsigned-type that does not have the PartialOrd-trait?
Edit: To clarify: What I would love is a way to say "T has to have one of the types u8...u128 (and maybe BigUInt)" and then have Rust to automatically see "since T is of one of those types, the following traits have to be implemented for T: std::cmp::PartialOrd, std::ops::SubAssign, ..."