A slice is a view into contiguous data—&[T] for arrays/vectors, &str for UTF-8 strings. Slices borrow; they do not own.
String slice
let s = String::from("hello world");
let hello: &str = &s[0..5];
Important interview questions and answers
- Q: &str vs String?
A: String owns heap data; &str borrows a UTF-8 slice—often from a String or literal.
Self-check
- Do slices own their data?
- What type is a string literal like
"hi"?