Rust Slices (&[T]): Views Without Ownership
A Rust slice is a borrowed view into a contiguous sequence of data, like an array or Vec, without taking ownership. Use it to write functions that operate on parts of a collection efficiently. The footgun: a slice cannot outlive the data it points to.
A Rust slice (`&[T]`) is a "fat pointer"—a pointer plus a length—that provides a view into a block of data owned by something else, like a `Vec` or an array. It lets you write flexible functions that can operate on any sequence without copying or taking ownership. The main footgun is lifetime errors: the compiler stops you if the slice might outlive the original data, preventing dangling pointers.
Read the original → doc.rust-lang.org
- #rust
- #memory-management
- #data-structures
- #borrowing
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.