Strings
String
is the dynamic heap string type. When you need to modify or own the string. str
is an immutable sequence of UTF-8 characters. A 'slice' of string data. Used behind a reference as &str
.
To make a String
from a &str
: String::from("foo")
or "foo".to_string()
or let foo: String = "Hello world".into()
Literal Strings
Modifying Strings
String
is mutated via .push_str(&str)
.