Swagger complex response model with dynamic key value hash maps

Your usage of additionalProperties is correct and your model is correct. additionalProperties In Swagger/OpenAPI, hashmap keys are assumed to be strings, so the key type is not defined explicitly. additionalProperties define the type of hashmap values. So, this schema type: object additionalProperties: type: string defines a string-to-string map such as: { “en”: “English text”, “de”: … Read more

How can I update a value in a mutable HashMap?

Indexing immutably and indexing mutably are provided by two different traits: Index and IndexMut, respectively. Currently, HashMap does not implement IndexMut, while Vec does. The commit that removed HashMap‘s IndexMut implementation states: This commit removes the IndexMut impls on HashMap and BTreeMap, in order to future-proof the API against the eventual inclusion of an IndexSet … Read more

How do I create a HashMap literal?

There isn’t a map literal syntax in Rust. I don’t know the exact reason, but I expect that the fact that there are multiple data structures that act maplike (such as both BTreeMap and HashMap) would make it hard to pick one. Rust 1.56 Many collections now offer conversions from an array argument using From … Read more

How to lookup from and insert into a HashMap efficiently?

The entry API is designed for this. In manual form, it might look like let values = match map.entry(key) { Entry::Occupied(o) => o.into_mut(), Entry::Vacant(v) => v.insert(default), }; One can use the briefer form via Entry::or_insert_with: let values = map.entry(key).or_insert_with(|| default); If default is already computed, or if it’s OK/cheap to compute even when it isn’t … Read more