Use String when you need to own and modify text, and &str when you only need to read a borrowed slice of text. String lives on the heap and is mutable, while &str is a reference to a string literal or part of a String that lives on the stack or elsewhere.
fn main() {
let owned = String::from("hello");
let borrowed: &str = "world";
println!("{owned}, {borrowed}");
}