4 ms·
String literals have the type "&'static str", that is, an immutable reference to a string that lives for the entire program. As a reference, it doesn't have own
by steveklabnik 10y ago
String literals have the type "&'static str", that is, an immutable reference to a string that lives for the entire program. As a reference, it doesn't have ownership over its contents.
String is a growable, changable, string type. String::from will convert a &str to a String. It does have ownership over its contents.
String is needed here because when you read something at runtime, you're not going to have a literal, of course. But when you're creating something from a literal, you'll have to convert it to a String.
For a _much much_ more in-depth explanation that you don't need a _ton_ of Rust knowledge to understand, see http://rust-lang.github.io/book/ch04-00-understanding-ownership.html http://rust-lang.github.io/book/ch04-00-understanding-owners... (and its three sub-sections)