#macro #hash-map #literals #vector

velcro

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

14 releases

0.5.4 Jan 1, 2023
0.5.3 Jan 15, 2021
0.5.2 Dec 20, 2020
0.4.4 Dec 9, 2020
0.1.2 Nov 25, 2020

#226 in Data structures

Download history 711/week @ 2023-12-11 922/week @ 2023-12-18 681/week @ 2023-12-25 518/week @ 2024-01-01 1035/week @ 2024-01-08 1803/week @ 2024-01-15 954/week @ 2024-01-22 843/week @ 2024-01-29 960/week @ 2024-02-05 1716/week @ 2024-02-12 1386/week @ 2024-02-19 1461/week @ 2024-02-26 1126/week @ 2024-03-04 1407/week @ 2024-03-11 1076/week @ 2024-03-18 1461/week @ 2024-03-25

5,148 downloads per month
Used in 33 crates (16 directly)

Unlicense OR MIT

18KB

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");

Help

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

Dependencies

~1.5MB
~34K SLoC