---
source: https://iinventedlight.com/library/notes/rust-strings-utf8.md
title: "Rust Strings and UTF-8 text"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "MIT OR Apache-2.0 (rust-lang/book; Copyright (c) 2010 The Rust Project Developers); additional cited sources under MIT OR Apache-2.0; prose restates cited source lines in own words"
license_family: rust-mit
attribution: "Summary by iinventedlight (AI-assisted). Sources: The Rust Project (The Rust Programming Language book), Storing UTF-8 Encoded Text with Strings, MIT OR Apache-2.0; Rust by Example (rust-lang/rust-by-example), Strings - Rust By Example, MIT OR Apache-2.0. Notices: The Rust Programming Language book (rust-lang/book): Copyright (c) 2010 The Rust Project Developers; MIT OR Apache-2.0, used under MIT (https://github.com/rust-lang/book/blob/main/LICENSE-MIT). Rust by Example (rust-lang/rust-by-example): Copyright (c) 2014 Jorge Aparicio; MIT OR Apache-2.0, used under MIT (https://github.com/rust-lang/rust-by-example/blob/master/LICENSE-MIT)."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-09
status: published
approved_by: "Cole Withington, 2026-11-09 13:40 PT: \"Yes, publish all 15 Rust drafts\""
checked_on: 2026-11-09
as_of: 2026-11-09
confidence: medium
untested: "No Rust code was run for this note; only the fetched documentation pages were read."
category: coding-references
topic_area: "code-systems: Rust strings"
tags: [rust, strings, utf-8, ownership]
client: Librarian
sources:
  - id: S1
    title: "Storing UTF-8 Encoded Text with Strings"
    publisher: The Rust Project (The Rust Programming Language book)
    url: https://doc.rust-lang.org/book/ch08-02-strings.html
    accessed: 2026-11-09
    license: "MIT OR Apache-2.0"
  - id: S2
    title: "Strings - Rust By Example"
    publisher: Rust by Example (rust-lang/rust-by-example)
    url: https://doc.rust-lang.org/rust-by-example/std/str.html
    accessed: 2026-11-09
    license: "MIT OR Apache-2.0"
---
# Rust Strings and UTF-8 text

**Answer:** Rust strings use UTF-8 encoding. The common types are owned `String` and borrowed `&str`.

## String and str

A `String` is stored as a vector of bytes guaranteed to be valid UTF-8. `&str` is a slice view onto valid UTF-8 bytes.

## Indexing

Indexing a `String` with `[]` is discouraged: the return type of that operation is unclear. Use `.chars()` or `.bytes()` rather than ambiguous string indexing.

## Claims

- id: C1
  claim: Strings are UTF-8 encoded.
  source: S1
  evidence: "strings are UTF-8 encoded, so we can include any properly encoded data in them, as"
- id: C2
  claim: Indexing into a String is often a bad idea.
  source: S1
  evidence: "indexing into a String is complicated by the differences between how people and computers interpret"
- id: C3
  claim: The two most used string types are String and &str.
  source: S2
  evidence: "The two most used string types in Rust are String and &str."
- id: C4
  claim: A String is stored as a vector of bytes guaranteed UTF-8.
  source: S2
  evidence: "A String is stored as a vector of bytes (Vec<u8>), but guaranteed to always be"

## Sources

- [S1] Storing UTF-8 Encoded Text with Strings. The Rust Project (The Rust Programming Language book). https://doc.rust-lang.org/book/ch08-02-strings.html . License: MIT OR Apache-2.0. Accessed 2026-11-09.
- [S2] Strings - Rust By Example. Rust by Example (rust-lang/rust-by-example). https://doc.rust-lang.org/rust-by-example/std/str.html . License: MIT OR Apache-2.0. Accessed 2026-11-09.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources and notices: The Rust Programming Language book (rust-lang/book): Copyright (c) 2010 The Rust Project Developers; MIT OR Apache-2.0, used under MIT (https://github.com/rust-lang/book/blob/main/LICENSE-MIT). Rust by Example (rust-lang/rust-by-example): Copyright (c) 2014 Jorge Aparicio; MIT OR Apache-2.0, used under MIT (https://github.com/rust-lang/rust-by-example/blob/master/LICENSE-MIT). Text was condensed and changed from the originals.

---

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