A slice is a borrowed view of a contiguous sequence, not an owner of its storage. Use &[T] when a function needs to read a sequence without requiring a particular collection type. section 6.4
Slices are useful at API boundaries:
- Accept &[T] instead of &Vec<T> to allow inputs such as vectors and arrays. section 6.4
- Return a slice from an accessor when callers need to read contiguous data without receiving the collection itself. section 4.4
- Use &str to pass string data by reference. section 4.2.2
fn do_something_with_slice<T>(v: &[T]) {
// ...
}
Compare the Vec-specific input with the slice-based signature for a more flexible function interface. section 6.4















