Ich versuche, diese einfache Code-Kompilierung zu machen:Rostfunktion hat keine statische Lebensdauer?
fn dox(x: u8) -> u8 { x*2 }
fn main() {
let cb: &'static (Fn(u8) -> u8) = &dox;
}
aber es funktioniert nicht mit Rust 1,9:
x.rs:4:40: 4:43 error: borrowed value does not live long enough
x.rs:4 let cb: &'static (Fn(u8) -> u8) = &dox;
^~~
note: reference must be valid for the static lifetime...
x.rs:4:44: 5:2 note: ...but borrowed value is only valid for the block suffix following statement 0 at 4:43
x.rs:4 let cb: &'static (Fn(u8) -> u8) = &dox;
x.rs:5 }
error: aborting due to previous error
Wie ist es möglich, dass eine freie Funktion nicht statisch Lebensdauer hat? Wie könnte dieser Code unsicher sein?