Skip to content

to_sorted_vec

The elements of set as a sorted Vec.

A HashSet iterates in an unspecified order that changes between runs; use this wherever the order is visible (output, snapshots, tests).

use helpers4::set::to_sorted_vec;

Cargo feature set (enabled by default). To compile only this module:

cargo add helpers4 --no-default-features --features set

or in Cargo.toml:

[dependencies]
helpers4 = { version = "0.0.6", default-features = false, features = ["set"] }
pub fn to_sorted_vec<T: Clone + Ord, S: BuildHasher>(set: &HashSet<T, S>) -> Vec<T>
ParameterTypeDescription
set&HashSet<T, S>The set to list.

Vec<T> — The elements in ascending order.

use helpers4::set::to_sorted_vec;
use std::collections::HashSet;

let set = HashSet::from([3, 1, 2]);
assert_eq!(to_sorted_vec(&set), vec![1, 2, 3]);

src/set/to_sorted_vec.rs