Create a **function**`calculate_macros` which receives a vector of `serde_json::Value` and returns a `serde_json::Value`.
Create a **function**`calculate_macros` which receives a vector of `Food` structures and returns a `json::JsonValue`.
The vector the function will receive will contain jsons in the following format:
```rust
Food {
```json
name: <name>,
{
calories: [<value_in_kJ>, <value_in_kcal>],
"name": <name>,
fats: <fats_in_g>,
"calories": [<value_in_kJ>, <value_in_kcal>],
carbs: <carbs_in_g>,
"fats": <fats_in_g>,
proteins: <proteins_in_g>,
"carbs": <carbs_in_g>,
nbr_of_portions: <portions>
"proteins": <proteins_in_g>,
"nbr_of_portions": <portions>
}
}
```
```
The name and the content of the calories array will be `strings`, all other values will be `floats`.
Both values in the calories array will be `strings`, all other values will be `f64`s.
The function should return a json with the following format (Macros struct):
The function should return a json with the following format (Macros struct):
@ -32,13 +30,23 @@ The number of portions should be taken into account. The values of the macros re
All values should be floats (f64) and should be the addition of every macronutrient in the provided array (cals is the addition of every calories, fats is the addition of every fats, and so on...).
All values should be floats (f64) and should be the addition of every macronutrient in the provided array (cals is the addition of every calories, fats is the addition of every fats, and so on...).
Every value should be rounded to two decimal places (ex: 12.29) or one decimal place if it ends in 0 (ex: 18.90 -> 18.9).
Every value should be rounded to two decimal places (ex: 12.29) or one decimal place if it ends in 0 (ex: 18.90 -> 18.9).
Hint: You will need the `serde`, `serde_json` and `serde_derive` crates.