Skip to main content

Values

Struct Values 

Source
pub struct Values<'a, K, V> { /* private fields */ }
Expand description

An iterator over the values of a HashMap in arbitrary order. The iterator element type is &'a V.

This struct is created by the values method on HashMap. See its documentation for more.

ยงExamples

use rune::alloc::HashMap;

let map: HashMap<_, _> = [(1, "a"), (2, "b"), (3, "c")].try_into()?;

let mut values = map.values();
let mut vec = vec![values.next(), values.next(), values.next()];

// The `Values` iterator produces values in arbitrary order, so the
// values must be sorted to test them against a sorted array.
vec.sort_unstable();
assert_eq!(vec, [Some(&"a"), Some(&"b"), Some(&"c")]);

// It is fused iterator
assert_eq!(values.next(), None);
assert_eq!(values.next(), None);