Skip to content

Instantly share code, notes, and snippets.

@csknk
Forked from rust-play/playground.rs
Last active August 19, 2020 20:33
Show Gist options
  • Save csknk/bf3cce9426cedec6d3ce9758dcbed382 to your computer and use it in GitHub Desktop.
Save csknk/bf3cce9426cedec6d3ce9758dcbed382 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 - builds new String, which is moved out
// s + "s"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment