Explicit return borrowing fun

This commit is contained in:
Dan Buch 2017-12-30 08:49:54 -05:00
parent f9bbf54552
commit e8ab9ba3de
Signed by: meatballhat
GPG Key ID: 9685130D8B763EA7

View File

@ -1,11 +1,13 @@
fn main() {
let x = 5;
let y = x;
println!("x = {}, y = {}", x, y);
let s1 = String::from("hello");
let s2 = s1.clone();
println!("s1 = {}, s2 = {}", s1, s2);
let (s2, len) = calculate_length(s1);
println!("The length of '{}' is {}.", s2, len);
}
fn calculate_length(s: String) -> (String, usize) {
let length = s.len();
(s, length)
}