I am struggling with making some code faster and I think it would gain from parallelization. I have a vector that holds a struct with many fields that I want to aggregate (sum) the fields and produce a resulting structure that is similar but not identical to the one being aggregated.
If the struct was identical I would probably go about it by implementing the Sum Trait and doing a simple map followed by sum. However, in this scenario I'm afraid I don't see the clear path forward. How would you do it?
Here is a minimal working example: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=4059af4206dc3ac6e62690c2c8709543
Some things to note are that the struct to be aggregate has data types that consume less memory like u16 while the aggregated one may use something like u64 to store the sum of all the u16s. Also, at least one field may not need to be aggregated.
Please feel free to suggest different ways of doing things as well. I wonder for example if the type casting there (i.e. as u32) is the most idiomatic way of doing such a thing.
Thank you for your guidance!