when it is just a line allocated by the stack
This is not entirely correct. String slice ( &str) is conceptually built from two things:
- Pointer to the beginning of a line.
- The number of bytes per line.
A pointer can refer to data on the stack, to a heap, or even to persistent program data.
It is called a string slice because it reflects a regular slice ( &[T]), which is the same two parts: pointer and length.
u8 (&[u8]), : UTF-8.
, " " " " -, . :
let test_scores = [0, 10, 100];
let all_scores = &test_scores[..];
let some_scores = &test_scores[0..1];