String — owned, heap-allocated, mutable string. &str — borrowed, immutable string slice.
String:
String::from(), .to_string(), or format!().1let mut s = String::from("hello");2s.push_str(" world");3s.push('!');4println!("{}", s); // "hello world!"
&str:
"hello") are &str with static lifetime.1let literal: &str = "hello";2let owned = String::from("hello");3let slice: &str = &owned;4let part: &str = &owned[0..3]; // "hel"
When to use:
String when you need ownership and mutation.&str for read-only access (function params, comparisons).&str in API design for flexibility.Common mistakes:
s[0] doesn't work — use .chars().&String auto-derefs to &str.