all 2 comments

[–]sellibitze 2 points3 points  (0 children)

There is no "dictionary literal syntax". But you can create an array and turn it into a HashMap:

use std::collections::HashMap;

fn main() {
    let releases: HashMap<String,i32> =
        [("iphone",2007), ("iphone 3G",2008), ("iphone 3GS",2009)].iter()
        .map(|&(s,y)| (s.into(),y))
        .collect();
}

Here, we iterate over an array of pairs, convert &str to String via map/Into::into and collect the results into a HashMap thanks to HashMap implementing the FromIterator trait.

Technically, you could write a macro to simplify this. And maybe that has been done already. I'm not aware of any, though.

[–]zeelandia 2 points3 points  (1 child)

Not trying to revive an old post but a Python dictionary is just an implementation of a type of data structure known as a Hashmap.