Logo

Programming-Idioms

History of Idiom 8 > diff from v42 to v43

Edit summary for version 43 by freecoder:
[Rust] Added missing comma

Version 42

2018-12-17, 18:13:14

Version 43

2018-12-17, 18:14:33

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;
Imports
use std::collections::HashMap;
Code
let x: HashMap<&str, i32> = [
    ("one", 1),
    ("two", 2)
].iter().cloned().collect();
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
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
Demo URL
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=a4894d64bd00f4122fb7abdb7189cb09