Skip to content

Instantly share code, notes, and snippets.

@mizar
Created January 8, 2024 12:22
Show Gist options
  • Save mizar/90b5fa8678b30026b046ba5d46d7294c to your computer and use it in GitHub Desktop.
Save mizar/90b5fa8678b30026b046ba5d46d7294c to your computer and use it in GitHub Desktop.
use std::collections::HashMap;
fn greet_map(id: usize, name: String) -> HashMap<usize, String> {
let mut map = HashMap::new();
let message = format!("Hello, {}!", name);
map.insert(id, message);
map
}
fn main() {
let map = greet_map(0, String::from("world"));
for (&i, s) in map.iter() {
println!("{} {}", i, s);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment