Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created August 19, 2020 20:31
Show Gist options
  • Save rust-play/cce43d9ebf68e3399a414979ff9090eb to your computer and use it in GitHub Desktop.
Save rust-play/cce43d9ebf68e3399a414979ff9090eb to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
fn main() {
let s = String::from("book");
let ss = pluralize(s.clone());
println!("One {}, many {}", s, ss);
}
fn pluralize(s: String) -> String {
// Can't push_str directly onto s as s is not mutable
let mut p = s;
p.push_str("s");
return p
// This is ok
// s + "s"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment