split_at divides a slice at an index and returns two nonoverlapping slices. It applies to slices, arrays, and vectors, enabling multiple safe borrows of separate regions. section 4.2
let (first_half, second_half) = slice.split_at(32); #1
println!(
"first_half.len()={} second_half.len()={}",
first_half.len(),
second_half.len()
);
Borrow the first and second regions of a 64-element slice at index 32, then inspect their lengths. section 4.2
Use split_at when:
- A parser or decoder needs separate borrows into one array or slice. section 4.2
- You want contiguous memory handling without heap allocation in a fixed-size example. section 4.2
