Values & References1 / 18
Up next

Borrow to read

// &[i32] borrows any Vec or array without moving it
fn total(v: &[i32]) -> i32 {
    v.iter().sum()
}

fn main() {
    let nums = vec![1, 2, 3];
    println!("{}", total(&nums));
    // nums is still owned here
    println!("still have {} items", nums.len());
}
What you're solving

&[T] reads without taking ownership