Generic types operate with const?

Hi,
I am turning my whole library into a generic-type-based one. But I have some trouble.
For example, The present-form is like this:

fn foo(a:i32, b:i32) -> i32 {
   let mut bar: i32 = 1;
   for _ in 0..10 {
     bar = bar + a + b;
   }
   bar
}

But, when I'm going to convert this form into generic one, I do this:

fn foo<T: /* some traits */> (a:T, b:T) -> T {
   let mut bar: T = 1;
   for _ in 0..10 {
     bar = bar + a + b;
   }
   bar
}

Easy to see, this is the wrong code, but how to deal with adding (or subbing, etc.) between generic types and const?

Thank you!

You can use the num crate to get you additional type capabilities, such as the notion of One: playground.

1 Like

Thank you, I've already solved that