Something like this:
let source = [0u8; 40];
let a = source[0..11];
let b = source[11..40];
Something like this:
let source = [0u8; 40];
let a = source[0..11];
let b = source[11..40];
Use slice::split_at
:
fn main() {
let source = [0u8; 40];
let (a, b) = source.split_at(11);
println!("{}, {}", a.len(), b.len())
}
There's also split_at_mut
, discussed in How to operate on 2 mutable slices of a Rust array.
In this case, you can also take multiple subslices because it's immutable. These may be overlapping:
fn main() {
let source = [0u8; 40];
let a = &source[0..11];
let b = &source[11..40];
println!("{}, {}", a.len(), b.len())
}
into couple of copies?
The point of slices is that copies aren't made. A slice is just a pointer to the start of the data and a length. The data itself is shared.
I want to make 'a' and 'b' arrays instead of slices
Then you should check out How to get a slice as an array in Rust?