Exercise 2 · Chapter: Ownership & BorrowingRequired+50 XP
Borrow to Print
Write a function called show that borrows a String and prints it. Then call show from main and print the string again after the call to prove it's still valid.
Expected output:
Showing: Rust Still have: Rust
Hints:
- The function signature should be
fn show(text: &String) - Pass the string with
&my_string - After calling
show, the string is still yours to use!
rust
fn main() {
}
Output
Run your code to see the output here.