A Vec
-like datastructure which only contains unique entries. It is no_std
and provides optional serde
support.
// Create a new empty UniqueVec
use uniquevec::UniqueVec;
let mut uvec = UniqueVec::new();
// Fill it with contents
uvec.push("cellular");
uvec.push("_");
uvec.push("raza");
// The next entry is already contained so it will not be added again.
// We can also check the returned value
let r = uvec.push("cellular");
assert_eq!(r, Some("cellular"));
// Otherwise we can use it similarly to a Vec
assert_eq!(uvec[0], "cellular");
assert_eq!(uvec[1], "_");
assert_eq!(uvec[2], "raza");
assert_eq!(uvec.len(), 3);
for (n, entry) in uvec.into_iter().enumerate() {
println!("{n}th entry: {entry}");
}