我正努力做到这一点:
type Real = f64;
pub fn outer<F>(f1: &F, f2: &F) -> Box<Fn(&Real) -> Real>
where F: Fn(&Real) -> Real
{
Box::new(move |x| f1(x) + f2(x))
}
编译器一直在抱怨:
error[E0477]: the type `[closure@src/main.rs:6:14: 6:36 f1:&F, f2:&F]` does not fulfill the required lifetime
--> src/main.rs:6:5
|
6 | Box::new(move |x| f1(x) + f2(x))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: type must outlive the static lifetime
如何让它发挥作用?