You suggestion works (after removing some other lifetime specifiers that shouldn't be there). Thank you.
However I still don't understand your explanation; this must be how @ZiCog feels about monads
Are you saying that for some implementation of EconomicAgent
, the returned vector should be owned and contained by the implementor? (That is my interpretation of the word "point" when applied to references). My intention here is that the returned vector is a subset of the input vector.
This part really confused me. maker
and partially_settled
are different types so they are trivially different things, no? What have I misunderstood?
This is how I have finished off that bit of code, which seems to compile without complaints.
let partially_settled:Vec<&ProposedTrade> =
proposed_trades_map.into_iter().flat_map(|(maker_id, pts)|{
let maker = agent_col.agents.get_mut(&maker_id).unwrap();
maker.settle_maker_side(pts)
}).collect();
let partially_settled_map =
partially_settled.iter()
.map(|pt|(pt.taker_id, *pt))
.into_group_map();
for (taker_id, pts) in partially_settled_map.into_iter() {
let taker = agent_col.agents.get_mut(&taker_id).unwrap();
taker.settle_taker_side(pts);
}
Have I not taken another mutable borrow of the contents of agents
(which is what maker was earlier) whilst partially_settled
is still in scope?