UnordItems in rustc_data_structures::unord - Rust (original) (raw)

pub struct UnordItems<T, I: Iterator<Item = T>>(I);

Expand description

UnordItems is the order-less version of Iterator. It only contains methods that don’t (easily) expose an ordering of the underlying items.

Most methods take an Fn where the Iterator-version takes an FnMut. This is to reduce the risk of accidentally leaking the internal order via the closure environment. Otherwise one could easily do something like

let mut ordered = vec![];
unordered_items.all(|x| ordered.push(x));

It’s still possible to do the same thing with an Fn by using interior mutability, but the chance of doing it accidentally is reduced.

Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.