Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!
:timing
:sccache 1Tips and Traps¶
A slice is a dynamically-sized view into a contiguous sequence. It is basically a fat pointer which consists of a pointer and a length. For this reason, a slice has a len method. As a matter of fact, many methods of array and Vec are implemented via slice.
let v = vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9];&v[2..7][2, 3, 4, 5, 6]&v[2..][2, 3, 4, 5, 6, 7, 8, 9]&v[..4][0, 1, 2, 3]Nested Slices¶
Slices in Rust can be nested. That is, you can get (sub) slice out of a slice.
&v[2..7][1..3][3, 4]std::slice::binary_search¶
&v[2..7].binary_search(&8)Err(5)&v[2..7].binary_search(&4)Ok(2)