collect-all
A macro to create collection literals for any type! Think of
vec!, but for any collection
type!
Internally, this just uses the
Iterator::collect()
method. Since collect is powered by
FromIterator,
implement it to use this macro for your own types!
Examples
Basic use, inferring the type of the collection
use collect;
use HashSet;
let hashset: = collect!;
assert_eq!;
Specifying the type in the macro invocation
use collect;
use HashMap;
let hashmap = collect!;
assert_eq!;
Creating with a given capacity
use collect;
use PathBuf;
let pathbuf = collect!;
assert_eq!;
assert!;
Note that this relies on a few things that are not strictly guaranteed for a given collection:
with_capacityis a method of the target type (for example, seeVec::with_capacity)- The target type implements
Extend
License
This crate is licensed under the MIT license.