Why str is called string slice, if &str is an actual string slice?

Viewed 71

Why str is called string slice, if &str is an actual string slice?

1 Answers

Going by the documentation:

However, because they are dynamically sized types, you often don't see them in this basic form alone. You'll most often see them used with some form of indirection, be it reference, Box, Arc or "smart pointer" type. So strictly speaking, a &str is a "reference to string slice".

But the "reference to-" prefix is not particularly helpful in most contexts and is very wordy. So most will colloquially refer to &str as a "string slice" unless more precise terminology is warranted. If someone mentions a "slice", you know they're referring to a "dynamically-sized view into a contiguous sequence"; the exact construction of is not important to its meaning.

Related