如题所示,代码如下:
//函数式编程
fn callme<F>(t1:String,t2:String,f:F) where F:Fn(String,String){
f(t1,t2)
}
fn print(s1:String,s2:String){
println!("it is {} {}",s1,s2);
}
fn main() {
let f1 = |x,y|{println!("{}{}",x,y)};
callme("one arg".to_string()," two arg".to_string(), f1);
let f2 = print;
callme("第一个参数".to_string()," 第二个参数".to_string(), f2);
}
//输出结果
//one arg two arg
//it is 第一个参数 第二个参数