Complete the code to create a new empty String in Rust.
let mut s = String::[1]();from without an argument causes an error.push to create a String.The String::new() function creates a new empty String.
Complete the code to convert a string slice to a String.
let s = "hello".[1]();
clone on a &str does not create a String.push_str requires a mutable String.The to_string() method converts a string slice (&str) to a String.
Fix the error in the code to append a character to a String.
let mut s = String::new(); s.[1]('a');
append which expects a &str, not a char.add which is not a method on String.The push() method appends a single character to a String.
Fill both blanks to create a String from a &str and then get its length.
let s = String::[1]("hello"); let len = s.[2]();
to_string as a static method instead of on a &str.capacity instead of len for length.String::from("hello") creates a String from a string slice.len() returns the number of bytes in the String.
Fill both blanks to create a String, append a &str, and then print it.
let mut s = String::[1]("Hello"); s.[2](" World"); println!("{}", s);
push instead of push_str for &str.to_string on String before printing.String::from("Hello") creates the String.push_str(" World") appends the string slice.
Printing s directly shows the full string.
