Complete the code to create a new String and assign it to variable s.
let s = String::[1]("hello");
The String::from function creates a new String from a string literal.
Complete the code to transfer ownership of s1 to s2.
let s1 = String::from("hello"); let s2 = [1];
Assigning s1 to s2 moves ownership, so s1 is no longer valid.
Fix the error by completing the code to borrow s1 immutably.
let s1 = String::from("hello"); let len = calculate_length([1]); fn calculate_length(s: &String) -> usize { s.len() }
Passing &s1 borrows s1 immutably, matching the function parameter.
Fill both blanks to create a mutable String and append text to it.
let mut s = String::[1]("hello"); s.[2](" world");
new creates an empty string, not from literal.append is not a valid String method.String::from creates the string, and push_str appends text to it.
Fill all three blanks to create a function that takes ownership and returns the String.
fn takes_and_returns_[1](s: [2]) -> [3] { s } let s1 = String::from("hello"); let s2 = takes_and_returns_[1](s1);
string or str is incorrect type.The function takes ownership of a String and returns it, so parameter and return types are String.
