项目作者: peterjoel

项目描述 :
Collection initialization macros for Rust
高级语言: Rust
项目地址: git://github.com/peterjoel/velcro.git
创建时间: 2020-11-25T11:22:52Z
项目社区:https://github.com/peterjoel/velcro

开源协议:MIT License

下载


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

  1. use velcro::{hash_map, iter, vec};
  2. assert_eq!(vec![0, 1, ..(2..7)], vec![0, 1, 2, 3, 4, 5, 6]);
  3. let other = vec![3, 4, 5];
  4. assert_eq!(vec![0, 1, 2, ..&other, 6], vec![0, 1, 2, 3, 4, 5, 6]);
  5. let whitespace = iter![' ', '\t', '\r', '\n'];
  6. let map = hash_map! {
  7. ..('0'..='9'): "digit",
  8. ..('a'..='z'): "lower",
  9. ..('A'..='Z'): "upper",
  10. ..whitespace: "whitespace",
  11. '.': "punctuation",
  12. ',': "punctuation",
  13. };
  14. assert_eq!(map[&'x'], "lower");
  15. assert_eq!(map[&'\r'], "whitespace");
  16. assert_eq!(map[&'.'], "punctuation");

Help

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