Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created August 22, 2019 08:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rust-play/74a7665d7fba5b3ebf53a6544a3b522e to your computer and use it in GitHub Desktop.
Save rust-play/74a7665d7fba5b3ebf53a6544a3b522e to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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