String is an owned, growable UTF-8 text type, while str is an unsized slice type used for immutable references to string data.
In Rust, str is an unsized type representing a UTF-8 string slice, while String is a growable, owned string type that lives on the heap. Use &str for immutable references to string data and String when you need to own or modify the text.
let owned: String = String::from("hello");
let slice: &str = &owned;
Think of String as a text document you own and can edit, while str is just a view of some text you are reading. You use String when you need to create or change text, and &str when you just need to read text without taking ownership.