This is too cumbersome to do everytime you want to use a value without necessarily owning it. What if we want to let a function use a value but not take ownership?

Rust fixes this with references.

fnmain(){lets1=String::from("hello");// calculate_length gets a reference to s1, and so doesn't own s1.
letlen=calculate_length(&s1);println!("The length of '{}' is {}.",s1,len);}fncalculate_length(s: &String)-> usize{s.len()}

Having references as function parameters is called borrowing.

A function that accepts a reference can’t modify the data it refers to, unless it’s a mutable reference: