3 ms·
Given fn foo(x: &str) -> &str { x } calling `let z = foo(y);` is valid. The lifetime of `y` conforms to the lifetime of `x` in the `foo` signature,
by estebank 6y ago
Given
fn foo(x: &str) -> &str {
x
}
calling `let z = foo(y);` is valid. The lifetime of `y` conforms to the lifetime of `x` in the `foo` signature, while the lifetime of `z` can be as long as the one for `x` (up to x's lifetime), but it is shorter (unless you try to do `drop(y)`, which would be a borrow checker error).
- Arnavion 6y agoOkay, so you were talking about it from the POV of the caller, not the function. In that case, you meant "at most", not "at least". That is: >while an &'a returned borrow means "something that lives at most up to 'a, but might live less".