Exercise 10 · Chapter: Ownership & BorrowingRequired+50 XP
Ownership Transfer
Write a function make_greeting that takes ownership of a String name and returns a new String with a greeting. Print the result in main.
Expected output:
Welcome, Ferris!
Hints:
- Function signature:
fn make_greeting(name: String) -> String - Use
format!("Welcome, {}!", name)to build the new string - The function takes ownership, so
namemoves in — that's OK since we return a new string
rust
fn main() {
}
Output
Run your code to see the output here.