I believe that this function declaration tells Rust that the lifetime of the function\'s output is the same as the lifetime of it\'s s
parameter:
fn
The <'a>
annotation just declares the lifetimes used in the function, exactly like generic parameters
.
fn subslice<'a, T>(s: &'a [T], until: u32) -> &'a [T] { \\'
&s[..until as usize]
}
Note that in your example, all lifetimes can be inferred.
fn subslice(s: &[T], until: u32) -> &[T] {
&s[..until as usize]
}
fn substr(s: &str, until: u32) -> &str {
&s[..until as usize]
}
playpen example