That's a very common question, and a rather comprehensive answer can be found over here. Basically the difference is that a String
is a thing that owns an allocation, while a &str
is a slice into some allocation owned by something else.
A common misconception is that &str
is the immutable version of String
, but if you build from this assumption, you will run into lifetime troubles.