idiom#8 构造map
Initialize a new map (associative array)
Python
x = {"one" : 1, "two" : 2}
Rust
#![allow(unused)] fn main() { use std::collections::HashMap; let x: HashMap<&str, i32> = [ ("one", 1), ("two", 2), ].into_iter().collect(); use std::collections::BTreeMap; let mut x = BTreeMap::new(); x.insert("one", 1); x.insert("two", 2); }
Elixir
x = %{"one" => 1, "two" => 2}
x = %{one: 1, two: 2}
Humm?
和 Python 基本相似; 不过, Rust 明显有更多内建模块支持各种姿势的嗯哼...
_~∽~∽~_
\/ / = ◴ \ \/
'_ ⎵ _'
( '-----' )
...act by ferris-actor v0.2.4 (built on 23.0303.201916)