我正在尝试在Rust写一个小程序,但我无法让它工作.
我在一个较小的脚本中重现了错误:
fn main() {
let name = String::from("World");
let test = simple(name);
println!("Hello {}!", test())
}
fn simple<T>(a: T) -> Box<Fn() -> T> {
Box::new(move || -> T {
a
})
}
Run Code Online (Sandbox Code Playgroud)
当我编译它时,我收到此错误:
error[E0310]: the parameter type `T` may not live long enough
--> test.rs:8:9
|
7 | fn simple<T>(a: T) -> Box<Fn() -> T> {
| - help: consider adding an explicit lifetime bound `T: 'static`...
8 | / Box::new(move || -> T {
9 | | a …Run Code Online (Sandbox Code Playgroud)