Generic arithmetic with std::ops::Add?

You can write:

use std::ops::Add;

fn double_it<T>(x: T) -> T
where T: Add<Output=T> + Copy + Clone {
    x + x
}

fn main() {
    println!("{}", double_it(21));
}
2 Likes