Conceptual
Login

Slices in Rust

A slice &[T] is a fat pointer — data pointer plus length — borrowing a contiguous run of elements owned by an array, Vec, or String. Indexing is bounds-checked against the stored length, and the slice can never outlive its backing storage.

Questions this Concept answers

  • Why is a slice a better argument type than a bare pointer for a buffer a driver is about to read?