Created
August 22, 2019 08:07
-
-
Save rust-play/74a7665d7fba5b3ebf53a6544a3b522e to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let s1 = String::from("hello"); | |
let (s2, len) = calculate_length(s1); | |
println!("The length of '{}' is {}.", s2, len); | |
} | |
fn calculate_length(s: String) -> (String, usize) { | |
let length = s.len(); // len() returns the length of a String | |
(s, length) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment