Core Intermediate
07 Ownership
The heart of Rust. These functions take ownership when they shouldn't -- borrow instead, so the caller keeps its values.
Fix total_len so it borrows the vec and the caller can still use it.
Hints
- Passing by value moves; borrow with
&[T]to read. - The check calls
total_len(&v)-- match that.
Reveal solution
fn total_len(items: &[String]) -> usize {
items.iter().map(|s| s.len()).sum()
}