std-method
slice::last
Borrow the final element without computing length minus one, which would be invalid for an empty slice. Expected stdout (not executed): Some(10) Common mistake: Computing len() - 1 before testing for an empty input.
Formal Syntax & Structure
rust syntaxrust
slice.last() -> Option<&T>Working Example
Example Snippetrust
fn main() { let values = [8, 9, 10]; println!("{:?}", values.last());}