Explicit return borrowing fun
This commit is contained in:
parent
f9bbf54552
commit
e8ab9ba3de
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user