to_vec()in rust
2023-04-18
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 aVec
. For example: -
ToVecResult
: Collects an iterator ofResult<T, E>
into aResult<Vec<T>, E>
, where the error is the first error encountered.
Some other similar crates
-
ToSet
: Collects an iterator of references into aHashSet
, implicitly cloning the items. -
ToMap
: Collects an iterator of references to key-value pairs into aHashMap
, implicitly cloning the keys and values.
These specialized forms provide a more ergonomic and efficient way to collect iterators into commonly used containers.
This is done with the help of phined