Understanding when to use String vs str - help - The Rust Programming Language Forum
users.rust-lang.org/t/understanding-when-to-use-string-vs-str/103746Hey everyone, new to Rust and just checking my high level understanding of String vs str. A String type is a container for a str that is stored on the heap. String keeps the ownership, str is simply a reference and will most commonly be seen as &str. The heuristic I have in my head is that a String type should only be seen as part of the type that owns it. For example, as part of a struct definition. When being passed into methods, or returning data from a method, then use an &str type as thi...