#macro #collection #initialization #breaking #internal #operator #velcro

velcro_core

Core dependencies used by the velcro crate. See velcro for documentation. It is not advised to depend on this crate directly; it is an internal dependency of velcro and may be subject to breaking changes.

8 releases

0.5.4 Jan 1, 2023
0.5.2 Jan 15, 2021
0.5.1 Dec 20, 2020
0.4.2 Dec 9, 2020
0.3.0 Dec 2, 2020

#2485 in Rust patterns

Download history 520/week @ 2023-12-04 716/week @ 2023-12-11 927/week @ 2023-12-18 685/week @ 2023-12-25 521/week @ 2024-01-01 1031/week @ 2024-01-08 1806/week @ 2024-01-15 956/week @ 2024-01-22 845/week @ 2024-01-29 963/week @ 2024-02-05 1718/week @ 2024-02-12 1387/week @ 2024-02-19 1463/week @ 2024-02-26 1128/week @ 2024-03-04 1402/week @ 2024-03-11 1086/week @ 2024-03-18

5,193 downloads per month
Used in 35 crates (via velcro_macros)

Unlicense OR MIT

30KB
817 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");

Help

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

Dependencies

~1.5MB
~34K SLoC