[−][src]Crate velcro
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
btree_map | An initializer for |
btree_map_from | An initializer for |
btree_set | An initializer for |
btree_set_from | An initializer for |
hash_map | An initializer for |
hash_map_from | An initializer for |
hash_set | An initializer for |
hash_set_from | An initializer for |
iter | Creates an iterator, over the given values. Other collections and iterators
may also be interspersed, or "spread", using the |
iter_from | Creates an iterator, over the given values. Works the same as |
linked_list | An initializer for |
linked_list_from | An initializer for |
map_iter | Creates an iterator over pairs of values, expressed with map-like syntax.
Other collections and iterators may also be interspersed, or "spread", using the
|
map_iter_from | Creates an iterator over pairs of values in the same way as |
vec | A more flexible vector initialization macro. |
vec_from | Works the same as |