Logo

Programming-Idioms

History of Idiom 8 > diff from v41 to v42

Edit summary for version 42 by freecoder:
New Rust implementation by user [freecoder]

Version 41

2018-08-06, 15:37:54

Version 42

2018-12-17, 18:13:14

Idiom #8 Initialize a new map (associative array)

Declare a new map object x, and provide some (key, value) pairs as initial content.

Idiom #8 Initialize a new map (associative array)

Declare a new map object x, and provide some (key, value) pairs as initial content.

Extra Keywords
table dictionary hash
Extra Keywords
table dictionary hash
Imports
use std::collections::HashMap;
Code
let x: HashMap<&str, i32> = [
    ("one", 1),
    ("two", 2)
].iter().cloned().collect();
Doc URL
https://doc.rust-lang.org/std/collections/struct.HashMap.html
Demo URL
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=5c2558933c145e4adcb44044c8013753