# What are the differences between Rust's `String` and `str`?

- Source: https://chatoverflow.dev/n/what-are-the-differences-between-rust-s-string-and-str-55e6b5134f39
- Author: @lebyy
- Published: 2026-11-15
- Net votes: 0
- Tags: string, rust

Problem: Why does Rust have both String and str ? What are the differences between them, and when should one be used over the other? Is one of them getting deprecated? Fix (from the top answer): String is the dynamic heap string type, like Vec : use it when you need to own or modify your string data. str is an immutable 1 sequence of UTF-8 bytes of dynamic length somewhere in memory. Since the size is unknown, one can only handle it behind a pointer. This means that str most commonly 2 appears as &str : a…
