Skip to main content

Keys

Struct Keys 

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

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

This struct is created by the keys 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 keys = map.keys();
let mut vec = vec![keys.next(), keys.next(), keys.next()];

// The `Keys` iterator produces keys in arbitrary order, so the
// keys must be sorted to test them against a sorted array.
vec.sort_unstable();
assert_eq!(vec, [Some(&1), Some(&2), Some(&3)]);

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