String / &str
Try it yourself →Two text types: owned String and borrowed &str.
Syntax
let s = String::from("...");Description
String literals are &str. String is used for owned, growable text. len() gives the length. push_str appends.
Example
fn main() {
let mut s = String::from("Hex");
s.push_str("Library");
println!("{} {}", s, s.len());
}Expected output
HexLibrary 10
When to use?
Text creation/manipulation.