Start with the idea
A parameter of type String takes ownership, while &str only borrows text. Read the signature before deciding whether the caller should keep using its value.
A function signature is an ownership map. fn inspect(text: &str) asks for temporary read access and lets the caller keep its String. fn store(text: String) takes ownership, so the caller cannot use that binding after the call unless the function returns it or the caller cloned it beforehand. A parameter like i32 is passed by value too, but i32 is Copy, which leaves the original usable. The syntax is the same; the type determines the effect.
Keep learning, for free
The rest of this lesson is waiting for you.
Create a free account to read the complete explanation, see the infographic, explore the code, and try the exercises. All 742 lessons and algorithm steps are included.
No payment details. Your account opens the complete Academy.