-
-
Save csknk/bf3cce9426cedec6d3ce9758dcbed382 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 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