How to initialize a variable with a lifetime?
I have following code and don't know how to get it working: fn new_int<'a>() -> &'a isize { &5 } fn main() { let x = new_int(); } Or another attempt: fn new_int<'a>() -> &'a isize { let a: &'a isize = &5; a } fn main() { let x = new_int(); } Paolo Falabella You can't. A lifetime parameter does not allow you to choose how long a value lives, it only allows you to communicate to the compiler that two or more references are "related" to the same memory and are expected to share the same lifetime. A function (like new_int in your case) can allocate memory in two ways: locally in an area (the stack