函数指针 Vec 是可以实现的,但是不知道如何实现闭包 Vec 。
type Bibao = dyn Fn(String)->String + 'static;
pub fn close_test4(){
let a = "456";
let b1: Bibao = move |mut s:String|{
s.push_str(a);
s
};
let mut v = Vec::new();
op1(b1,&v);
v.get(0)(String::from("123"));
}
fn op1<T:Fn(String) ->String>(t:T,mut v:&Vec<T>){
v.push(t);
}
报错:expected trait object `dyn std::ops::Fn`, found closure
求大佬指点。
type Bibao = dyn Fn(String)->String + 'static;
pub fn close_test4(){
let a = "456";
let b1: Bibao = move |mut s:String|{
s.push_str(a);
s
};
let mut v = Vec::new();
op1(b1,&v);
v.get(0)(String::from("123"));
}
fn op1<T:Fn(String) ->String>(t:T,mut v:&Vec<T>){
v.push(t);
}
报错:expected trait object `dyn std::ops::Fn`, found closure
求大佬指点。
