I'm trying to make a trait to work for all numeric integer types. I though that limiting it for num_traits::Num
would force it to be applicable only to u8, u16, etc so -1 would always work.
pub fn divide_round_up<T: num_traits::Num>(value: T, divisor: T) -> T {
return (value + divisor - 1) / divisor;
}
I get
|
19 | pub fn divide_round_up<T: num_traits::Num>(value: T, divisor: T) -> T {
| - this type parameter
20 | return (value + divisor - 1) / divisor;
| ^ expected type parameter `T`, found integer
What should I do here?
By the way, isn't there a way of doing this without the crate?