-
Notifications
You must be signed in to change notification settings - Fork 293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ability to build an object or hashmap? #898
Comments
This will be tremendously interesting to me. It will drastically reduce the number of parameters I have in macros and simplify a lot of code if optional fields can be grouped inside a single config object instead of each being a variable. A way to create a hash literal is needed as well as the ability to set a field of an object. |
@absolutejam your suggestion gives me an idea. We can very simply write such a function, say Until the native syntax arrives, this can be a huge boom in productivity as I can then write macros that take objects as parameters. EDIT: I confirm that the idea works. I have |
What's not defined yet is what would be the syntax to update a hashmap |
I solved it via a
will return a new map with the two properties replaced. Setting properties then become:
|
Yeah the filter is the obvious one, it's just a bit verbose to set new things but maybe it's the simpler one |
If you're looking for syntax suggestions, I suggest:
|
Or maybe just |
That would work too... In that case we can do |
Hey!
I'm trying to build some grouping functionality for my Zola blog and I wondered if it is currently possible (or planned) to build and mutate a JSON object or hashmap data structure?
For example, I'm currently iterating over an array of objects that each have their own tags.
I'd like to be able to group these objects into by their tags, ending up with a
Hashmap<String, Vec<MyObject>>
in rough Rust terms.It looks like this would probably want to live in https://github.com/Keats/tera/blob/master/src/builtins/filters/object.rs as this is already concerned with handling
serde_json::Value::Object
s?I'm happy to take a stab at this if you're okay with it 👍
The text was updated successfully, but these errors were encountered: