What a slice is
A slice `[T]` is a contiguous run of T values; you almost always work with the borrowed forms `&[T]` and `&mut [T]`. Internally a `&[T]` is a pointer plus a length. Slices erase the length's compile-time origin — a function taking `&[u8]` works the same on `&[u8; 16]`, `&Vec<u8>`, and a substring of either.
Indexing and slicing
`s[i]` returns `T` (or `&T` if T is unsized). `s.get(i)` returns `Option<&T>` for safe out-of-bounds handling. `s[i..j]` slices into a sub-slice. `s.first()`, `s.last()`, `s.split_first()`, `s.split_last()` cover the common boundary access patterns without panicking.
For deeper background, see a complete cheat-sheet of std collection complexities for the broader context behind this section.
Iteration adapters
`iter`, `iter_mut`, `chunks`, `chunks_mut`, `windows`, `split`, `splitn`, `rsplit`, `array_chunks`, `array_windows` cover the entire space of "walk this slice in some pattern." `chunks(n)` returns non-overlapping fixed-size slices; `windows(n)` returns overlapping ones. `split` and friends split on a predicate.
Sorting and searching
`sort` is a stable sort. `sort_unstable` is faster but doesn't preserve order of equal elements — use it when stability doesn't matter. `binary_search` requires the slice to be sorted. `partition_point` finds the boundary between elements satisfying a predicate and those not.
For deeper background, see the official Rust API guidelines for module-level design for the broader context behind this section.
Contiguous bytes and byteorder
`as_chunks` lets you split a slice into a slice of fixed-size arrays plus a remainder — useful for SIMD-friendly processing. For endianness conversion, use the `to_be_bytes` / `from_be_bytes` family on integer types and slice into the resulting array.