面试题答案
一键面试fn add_and_display<T: std::fmt::Display + std::ops::Add<Output = T>>(a: T, b: T) {
let result = a + b;
println!("{} + {} = {}", a, b, result);
}
你可以这样调用这个函数:
fn main() {
add_and_display(5, 3);
add_and_display("Hello, ".to_string(), "world!".to_string());
}