Exerpad
🔥 0
0 XP
Exercise 3 · Chapter: Ownership & BorrowingRequired+50 XP

Fix the Move

Oh no! This code tries to use a String after it was moved. Fix it so the program compiles and prints:

Hello, Luna!
Name is: Luna

Hint: Use borrowing (&) so the function doesn't take ownership!

rust
fn greet(name: String) {
println!("Hello, {}!", name);
}

fn main() {
let name = String::from("Luna");
greet(name);
println!("Name is: {}", name);
}
Output
Run your code to see the output here.