std-method
slice::split_first_chunk
Separate a fixed-size borrowed header from the variable-length body, or return None for insufficient input. Expected stdout (not executed): [10, 20] [30, 40, 50] Common mistake: Expecting an insufficient header to be padded automatically.
Formal Syntax & Structure
rust syntaxrust
slice.split_first_chunk::<N>()Working Example
Example Snippetrust
fn main() { let packet = [10, 20, 30, 40, 50]; let (header, body) = packet.split_first_chunk::<2>().unwrap(); println!("{header:?} {body:?}");}