What is the difference between String and str

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;