std-method
slice::split_first
Separate a borrowed first element from the remaining slice in one operation. A single-element input returns an empty remainder. Expected stdout (not executed): 5 [8, 13] Common mistake: Assuming the first element is removed from its owner.
Formal Syntax & Structure
rust syntaxrust
slice.split_first() -> Option<(&T, &[T])>Working Example
Example Snippetrust
fn main() { let data = [5, 8, 13]; if let Some((head, tail)) = data.split_first() { println!("{head} {tail:?}"); }}