to_vec is a crate that provides specialized implementations of collect for common use cases when collecting into Vec, HashSet, or HashMap containers. The main functionality can be broken down into:
ToVec: Collects an iterator's items into a Vec. For example:
#![allow(unused)]fnmain() {
use to_vec::ToVec;
let v = "one two three".split_whitespace().to_vec();
assert_eq!(v, &["one", "two", "three"]);
}
ToSet: Collects an iterator of references into a HashSet, implicitly cloning the items.
#![allow(unused)]fnmain() {
use to_vec::ToSet;
let colours = ["green", "orange", "blue"].iter().to_set();
let fruit = ["apple", "banana", "orange"].iter().to_set();
let common = colours.intersection(&fruit).to_set();
assert_eq!(common, ["orange"].iter().to_set());
}