Crates.io | more_collection_macros |
lib.rs | more_collection_macros |
version | 0.2.2 |
source | src |
created_at | 2022-01-30 03:17:12.408266 |
updated_at | 2022-02-15 06:27:07.331439 |
description | Adds new macros to rust for creating collections |
homepage | |
repository | https://github.com/joshradin/more_collection_macros |
max_upload_size | |
id | 523874 |
size | 9,046 |
By Joshua Radin
Repostiory
This library provides a set of useful macros for creating std collections, similar to the
default vec!
macro
These macros enable list/map comprehension similar to what's present in python. For example, the following python code
list = [x*x for x in range(0,10)]
dict = {x : x*x for x in range(0,10)}
is equivalent to the following rust code
let list = list![x*x; x in 0..10];
let dict = map!{x => x*x; x in 0..10};
With maps, you can also use identifiers as keys, which are then converted to &'static str
keys.
map!{
field1: 0,
field2: 1
};
You can't repeat fields with this notation. The following will give a runtime error.
map!{
field1: 0,
field1: 1
};