std-method
slice::split_last
Separate the final element from the preceding slice. Empty input returns None. The returned tuple puts the last element first. Expected stdout (not executed): 33: [11, 22] Common mistake: Destructuring the tuple as (prefix, last).
Formal Syntax & Structure
rust syntaxrust
slice.split_last()Working Example
Example Snippetrust
fn main() { let samples = [11, 22, 33]; let (last, earlier) = samples.split_last().unwrap(); println!("{last}: {earlier:?}");}