Rust String and &str: two UTF-8 string types
Answer: The core language string type is the string slice str, usually seen as &str. The standard library also provides String, which is growable, mutable, owned, and UTF-8 encoded.
Two types, both UTF-8
Rust has only one string type in the core language: the string slice str, usually written in borrowed form as &str.
String literals live in the program's binary, so they are string slices.
String comes from the standard library; it is not coded into the core language.
String and string slices are both UTF-8 encoded. Talk of strings in Rust can mean either type.
How String is stored
The two most used string types, according to Rust by Example, are String and &str.
String holds a vector of bytes and is guaranteed to always be a valid UTF-8 sequence.
It is heap allocated and growable, and it is not null terminated.
A &str slice always points to valid UTF-8 and can view into a String, much as &[T] views a Vec<T>.
See also
Claims
- id: C1 claim: The core language string type is the string slice str, usually seen as &str. source: S1 evidence: "string slice str that is usually seen in its borrowed form, &str"
- id: C2 claim: String is a growable, mutable, owned, UTF-8 encoded type from the standard library. source: S1 evidence: "growable, mutable, owned, UTF-8 encoded string type"
- id: C3 claim: Both String and string slices are UTF-8 encoded. source: S1 evidence: "both String and string slices are UTF-8 encoded"
- id: C4 claim: String is heap allocated, growable, and not null terminated. source: S2 evidence: "heap allocated, growable and not null terminated"
Sources
- [S1] Storing UTF-8 Encoded Text with Strings. The Rust Programming Language. https://doc.rust-lang.org/book/ch08-02-strings.html . License: MIT OR Apache-2.0. Accessed 2026-11-23.
- [S2] Strings. Rust by Example. https://doc.rust-lang.org/rust-by-example/std/str.html . License: MIT OR Apache-2.0. Accessed 2026-11-23.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: The Rust Programming Language, Storing UTF-8 Encoded Text with Strings; Rust by Example, Strings. MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/book/main/LICENSE-MIT). Copyright the Rust Project Developers. MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/rust-by-example/master/LICENSE-MIT). Copyright the Rust Project Developers. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: The Rust Programming Language, Storing UTF-8 Encoded Text with Strings; Rust by Example, Strings. MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/book/main/LICENSE-MIT). Copyright the Rust Project Developers. MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/rust-by-example/master/LICENSE-MIT). Copyright the Rust Project Developers.
Cite this
iinventedlight. 2026. "Rust String and &str: two UTF-8 string types." iinventedlight Library, iil:note:ry2p5af5, version of 2026-11-23. https://iinventedlight.com/library/notes/rust-string-vs-str/. License: CC-BY-4.0.
@misc{iil_note_ry2p5af5,
author = {{iinventedlight}},
title = {{Rust String and \&str: two UTF-8 string types}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-23},
url = {https://iinventedlight.com/library/notes/rust-string-vs-str/},
note = {Permanent ID iil:note:ry2p5af5. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- rust-string-vs-str.schema.json (schema; CC-BY-4.0)
- rust-string-vs-str.table.json (table; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/rust-string-vs-str.md.