January 2019
Beginner to intermediate
554 pages
13h 31m
English
Any time there's a reference in a function or a type definition, there's a lifetime involved. Most of the time, you don't need to use explicit lifetime annotation is you code as the compiler is smart to infer them for you as a lot of information is already available at compile time about references.
In other words, these two function signatures are identical:
fn func_one(x: &u8) → &u8 { .. }fn func_two<'a>(x: &'a u8) → &'a u8 { .. }
In the usual case, the compiler has elided the lifetime parameter for func_one and we don't need to write it as func_two.
But the compiler can elide lifetimes only in restricted places and there are rules for elision. Before we talk about these rules, we need to talk about input ...
Read now
Unlock full access