This commit is contained in:
Dan Buch 2017-12-30 21:41:52 -05:00
parent e8ab9ba3de
commit 2c6ad398f1
Signed by: meatballhat
GPG Key ID: 9685130D8B763EA7

View File

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