#![allow(unused)]fnmain() {
use std::sync::Mutex;
structMyString<'a> {
data: &'astr,
}
fni_want_static_closure<F>(a: F)
where F: Fn() + 'static {}
fnprint_string<'a>(s: Mutex<MyString<'a>>) {
i_want_static_closure(move || { // error: this closure has lifetime 'a// rather than 'staticprintln!("{}", s.lock().unwrap().data);
});
}
}
ⓘ
In this example, the closure does not satisfy the 'static lifetime constraint.
To fix this error, you need to double check the lifetime of the type. Here, we
can fix this problem by giving s a static lifetime: