1 The type does not fulfill the required lifetime.
3 Erroneous code example:
12 fn i_want_static_closure<F>(a: F)
13 where F: Fn() + 'static {}
15 fn print_string<'a>(s: Mutex<MyString<'a>>) {
17 i_want_static_closure(move || { // error: this closure has lifetime 'a
18 // rather than 'static
19 println!("{}", s.lock().unwrap().data);
24 In this example, the closure does not satisfy the `'static` lifetime constraint.
25 To fix this error, you need to double check the lifetime of the type. Here, we
26 can fix this problem by giving `s` a static lifetime:
35 fn i_want_static_closure<F>(a: F)
36 where F: Fn() + 'static {}
38 fn print_string(s: Mutex<MyString<'static>>) {
40 i_want_static_closure(move || { // error: this closure has lifetime 'a
41 // rather than 'static
42 println!("{}", s.lock().unwrap().data);