Skip to main content

ValuesMut

Struct ValuesMut 

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

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

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

ยงExamples

use rune::alloc::prelude::*;
use rune::alloc::HashMap;

let mut map: HashMap<_, _> = [
    (1, "One".try_to_owned()?),
    (2, "Two".try_to_owned()?)
].try_into()?;

let mut values = map.values_mut();
values.next().unwrap().try_push_str(" Mississippi")?;
values.next().unwrap().try_push_str(" Mississippi")?;

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

assert_eq!(map.get(&1).unwrap(), &"One Mississippi".try_to_owned()?);
assert_eq!(map.get(&2).unwrap(), &"Two Mississippi".try_to_owned()?);