String vs &str for owned vs borrowed text

2354
0

String is an owned, growable UTF-8 string on the heap. &str is a borrowed string slice, often a view into a String or a string literal. I use String when I need to own, modify, or build strings. I use &str for function parameters (accepting both String and literals) and when I don't need ownership. Converting: String::from("...") or .to_string() creates a String; &my_string or &my_string[..] creates a &str. Most string APIs accept &str to be flexible. Understanding the difference is key to avoiding unnecessary allocations and ownership issues. This is one of the first patterns new Rustaceans learn.