Lesson
1 / 4References
Borrow a value with &. The original owner keeps ownership.
main.rs
fn calculate_length(s: &String) -> usize {
s.len()
}
let s1 = String::from("hello");
let len = calculate_length(&s1); // borrow s1
println!("{} has length {}", s1, len); // s1 still valid!📖
Borrow the book, return it later