Skip to content

Instantly share code, notes, and snippets.

@NebulaFox
Last active March 17, 2020 13:54
Show Gist options
  • Save NebulaFox/5a254d38a5cf7b5806866b15cc920352 to your computer and use it in GitHub Desktop.
Save NebulaFox/5a254d38a5cf7b5806866b15cc920352 to your computer and use it in GitHub Desktop.
How long is a piece of string with make a string with another string
use rand; // 0.7.3
use rand::Rng;
fn make_a_string_with(string: &str) -> String {
let mut s = String::new();
s.push_str(string);
let mut rng = rand::thread_rng();
let r = rng.gen_range(0, 100);
for _ in 0..r {
s.push_str("!");
}
s
}
fn main() {
// how long is a piece of string
let s = make_a_string_with("Hello World");
println!("len: {}, string: {}", s.len(), s)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment