Skip to main content

One doc tagged with "slices"

View all tags

Slices as Borrows

After seeing how the Borrow Checker guarantees the validity of references, let's look at a special kind of reference that is ubiquitous in Rust: the slice. Slices provide a way to reference a contiguous sequence of elements in a collection rather than the whole collection. They are a powerful tool for writing expressive and efficient code that operates on portions of data, like a substring or a sub-array.