Get first element from HashMap

后端 未结 2 952
Happy的楠姐
Happy的楠姐 2020-12-21 04:32

I have a HashMap and need to get the first element:

type VarIdx = std::collections::HashMap;

fn get_first_elem(idx: VarIdx) ->         


        
2条回答
  •  青春惊慌失措
    2020-12-21 05:12

    HashMap::iter returns an iterator over (&Key, &Value) pairs. What you want is HashMap::values, which produces an iterator that only produces the values of the HashMap.

    Note that the order of the values is random. It has nothing to do with the order you put the values in or with the actual value of the values.

提交回复
热议问题