Skip to content

Instantly share code, notes, and snippets.

Created December 13, 2017 04:40
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 anonymous/f03a4aa626d0109bd1b0f3d6372d18f1 to your computer and use it in GitHub Desktop.
Save anonymous/f03a4aa626d0109bd1b0f3d6372d18f1 to your computer and use it in GitHub Desktop.
Rust code shared from the playground
use std::collections::HashMap;
fn main() {
let mut map = HashMap::new();
let words = vec!["quux", "bar", "floorgle", "bar"];
for word in words.iter() {
let word = *word;
let mut cond = false;
{
let x = map.entry(word).or_insert(0);
cond = *x < 3;
}
if cond {
let y = map.entry(words[word.len() % words.len()]).or_insert(0);
*y += 1;
println!("Hello, world!");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment