Expand description
Velcro
A set of macros for conveniently initializing collections from Rust’s std
and iterators. All of the macros support the unary ..
operator which “spreads”
the values of another collection or iterator.
velcro::vec!
is a drop-in replacement for std::vec!
. All functionality of
the std
macro is supported without overhead, but it also supports spreading values with the ..
operator.
Examples
use velcro::{hash_map, iter, vec};
assert_eq!(vec![0, 1, ..(2..7)], vec![0, 1, 2, 3, 4, 5, 6]);
let other = vec![3, 4, 5];
assert_eq!(vec![0, 1, 2, ..&other, 6], vec![0, 1, 2, 3, 4, 5, 6]);
let whitespace = iter![' ', '\t', '\r', '\n'];
let map = hash_map! {
..('0'..='9'): "digit",
..('a'..='z'): "lower",
..('A'..='Z'): "upper",
..whitespace: "whitespace",
'.': "punctuation",
',': "punctuation",
};
assert_eq!(map[&'x'], "lower");
assert_eq!(map[&'\r'], "whitespace");
assert_eq!(map[&'.'], "punctuation");
Contributing
Contributions are welcome! Check the Github issue tracker
for issues marked with good first issue
or help wanted
for issues that are reasonably complete in their description. Feel free to ask for
help or clarification by leaving comments on the issue.
This project uses Travis for continuous integration. Please check that your changes build and all of the tests pass:
- https://travis-ci.com/github/peterjoel/velcro
Help
For help, questions or to report an issue, please use the Github issue tracker.
Macros
BTreeMap
, allowing for entries to be specified individually
or for the same value to be given to multiple keys using the ..
operator.BTreeMap
that works the same as btree_map!
except that
values can be of any type that can be converted into the collection’s item
type via an Into
implementation.BTreeSet
, allowing for items to be specified individually
or “spread” using the ..
operator.BTreeSet
that works the same as btree_set!
except that
values can be of any type that can be converted into the collection’s item type.HashMap
, allowing for entries to be specified individually
or for the same value to be given to multiple keys using the ..
operator.HashMap
that works the same as hash_map!
except that
values can be of any type that can be converted into the collection’s item
type via an Into
implementation.HashSet
, allowing for items to be specified individually
or “spread” using the ..
operator.HashSet
that works the same as hash_set!
except that
values can be of any type that can be converted into the collection’s item
type via an Into
implementation...
operator.iter
except that values
may be any type that can be converted to the iterator item type via an Into
implementation.LinkedList
, allowing for items to be specified individually
or “spread” using the ..
operator.LinkedList
that works the same as linked_list!
except that
values can be of any type that can be converted into the collection’s item
type via an Into
implementation...
operator.map_iter
except
that values are converted into the expected type using an Into
implementation.velcro::vec!
is a
drop-in replacement for the built-in std::vec!
macro, but with extra
functionality. In particular, it adds the ..
spread operator, which
can insert multiple elements at once, provided that the expression
implements IntoIterator
, which is the case for all iterators and most
collections.vec!
except that values may be of any type that can be
converted into the item type via an implementation of Into
.