Slug: own-move-01 · Paired reading: Chapters 1 and 5
Prompt
Implement fn take_and_len(s: String) -> usize that returns the length of s.
Then explain — in a comment in your solution, and aloud — why a caller cannot
use s after passing it to take_and_len.
Predict first
Given let s = String::from("hi"); let n = take_and_len(s); println!("{s}");
— does it compile? Which error? What would go wrong at the end of the scope
if it did?
Rust angle
Moves transfer ownership; the borrow checker rejects use-after-move so that
exactly one owner runs Drop.