std-method
slice::split_at
Divide a shared slice into two views at an element boundary. The left side ends before mid. The method panics if mid is greater than the length. Expected stdout (not executed): [10] [20, 30, 40] Common mistake: Assuming mid is included in the left slice.
Formal Syntax & Structure
rust syntaxrust
slice.split_at(mid) -> (&[T], &[T])Working Example
Example Snippetrust
fn main() { let data = [10, 20, 30, 40]; let (header, payload) = data.split_at(1); println!("{header:?} {payload:?}");}