#vector #macro #hashmap #literal

velcro

Convenience macros for initializing vectors, hash maps and other Rust collections

13 releases (4 breaking)

0.5.3 Jan 15, 2021
0.5.2 Dec 20, 2020
0.4.4 Dec 9, 2020
0.3.0 Dec 2, 2020
0.1.2 Nov 25, 2020

#108 in Data structures

Download history 632/week @ 2021-06-06 909/week @ 2021-06-13 544/week @ 2021-06-20 696/week @ 2021-06-27 1093/week @ 2021-07-04 1005/week @ 2021-07-11 1122/week @ 2021-07-18 1122/week @ 2021-07-25 973/week @ 2021-08-01 1426/week @ 2021-08-08 909/week @ 2021-08-15 729/week @ 2021-08-22 521/week @ 2021-08-29 862/week @ 2021-09-05 610/week @ 2021-09-12 751/week @ 2021-09-19

2,029 downloads per month
Used in 8 crates (6 directly)

Unlicense OR MIT

22KB
101 lines

Velcro

Build Status

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 without errors and all of the tests pass:

Help

For help, questions or to report an issue, please use the Github issue tracker.

Dependencies

~340–760KB
~19K SLoC