---
source: https://iinventedlight.com/library/notes/rust-string-vs-str.md
title: "Rust String and &str: two UTF-8 string types"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "MIT OR Apache-2.0 (The Rust Programming Language); MIT OR Apache-2.0 (Rust by Example); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-23
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-23
as_of: 2026-11-23
confidence: medium
untested: "Not reproduced (2026-11-23). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-systems: rust-string-vs-str"
tags: [rust, string, str, types, systems]
client: Librarian
sources:
  - id: S1
    title: "Storing UTF-8 Encoded Text with Strings"
    publisher: The Rust Programming Language
    url: https://doc.rust-lang.org/book/ch08-02-strings.html
    accessed: 2026-11-23
    license: "MIT OR Apache-2.0"
  - id: S2
    title: "Strings"
    publisher: Rust by Example
    url: https://doc.rust-lang.org/rust-by-example/std/str.html
    accessed: 2026-11-23
    license: "MIT OR Apache-2.0"
---
# 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

- [rust-generics](https://iinventedlight.com/library/notes/rust-generics/)
- [rust-hashmap](https://iinventedlight.com/library/notes/rust-hashmap/)
- [rust-ownership-borrowing](https://iinventedlight.com/library/notes/rust-ownership-borrowing/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
