Skip to main content

Iter

Struct Iter 

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

An iterator over the entries of a HashMap in arbitrary order. The iterator element type is (&'a K, &'a V).

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

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

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