To find the range of all values in a hashmap in Rust, we can first retrieve an iterator of all values, then find the maximum and minimum values using the max()
and min()
functions respectively. Here's an example implementation:
main.rs517 chars22 lines
In this example, we create a new hashmap and insert some key-value pairs. Then we retrieve an iterator of all values using map.values()
, and find the maximum and minimum values using max()
and min()
respectively. Finally, we print the range of values. Note that we need to clone the values
iterator before calling max()
in order to satisfy the borrowing rules of Rust.
gistlibby LogSnag