std-method

slice::split_last_chunk

Separate a variable-length prefix from a fixed-size borrowed trailer. The prefix is the first tuple member. Expected stdout (not executed): [1, 2, 3] [8, 9] Common mistake: Assuming the trailer is the first tuple member like split_last.

Formal Syntax & Structure

rust syntaxrust
slice.split_last_chunk::<N>()

Working Example

Example Snippetrust
fn main() {    let packet = [1, 2, 3, 8, 9];    let (body, trailer) = packet.split_last_chunk::<2>().unwrap();    println!("{body:?} {trailer:?}");}
Rust Reference