1

I'm trying to make this work:

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))
}

The compiler keeps complaining:

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

How do I get this to work?

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Yi Zhang
  • 31
  • 4

0 Answers0