Declarative macros for creating dictionaries & arrays#140
Declarative macros for creating dictionaries & arrays#140alpha-tango-kilo wants to merge 4 commits intoebarnard:masterfrom
Conversation
Implementation & tests largely based on maplit (compatible license)
4ac4bad to
640f751
Compare
640f751 to
daa844f
Compare
Add example of repetition Shorten first example
|
Hey @ebarnard, can see you've been active on the repo again recently. Anything you need from me on this PR or my other one? |
|
#143 is looking to add a Also is it possible to use macros by path, e.g. |
|
isn't this more or less redundant as soon as #143 is ready? some examples for using Dictionary: let dict = plist!({
"a": 1,
"b": 2,
});Array: let array = plist!([1, 2, 3]); |
|
In some cases it's nice to have a |
Tried to see if I could make this work, but the trivial change from I'm not a dtolnay level macro wizard so am not really up to the task of rewriting this as a tt muncher. Maybe a I guess I've basically talked myself into having this PR closed in favour of #143 and maybe having these two more specialised macros added to that PR or built using it later
Doesn't look like it, no. Check out this experiment I made in Rust Playground: link |
These two types in particular can be a bit finnicky to build by hand, so I've made some declarative macros for the job based on the popular crate maplit
They pre-allocate the correct capacity ahead of time thanks to macro counting magics 🧙🏼♂️ (For this, I added
Dictionary::with_capacity, copying the documentation from the internalIndexMap)I could always make a separate crate for these if you didn't want them in the main repo, but I figured they're a useful addition. Happy to bikeshed the macro names, I just picked something so I could make the code work and debate later :)
As an aside, please consider adjusting workflow permissions for a better contributor experience: https://matklad.github.io/2022/10/24/actions-permissions.html