- All rust string types use UTF-8
stris a string literal. You never use this- Encoded into the program executable (in the
.dataportion of the ELF binary)
- Encoded into the program executable (in the
&stris a string slice- This is the borrowed type. You may use this, but not often
- It references either (1) the above
strencoded in the binary or (2) aStringclass
Stringis a string class- It has length, size, etc. all the information
- This is the **owned type
- You should probably use this.
- You can always pass a
&Stringinto a&str, because&stris just a reference; in this case it refers to theStringthat is allocated on the heap.
Abstract
A
Stringis a wrapper aroundstra string literal. The literal can live in stack or heap, depending on your program. The size is predetermined on compile-time, but you can change its contents.