In your example though, I don't see why you couldn't just make the connection vector hold a type parameter and add the second request with another type.
You mean something like this?
fn next_available() -> (usize, i64) { for (i, (orig_index, request)) in remaining_requests.iter().enumerate() { if Some(response) = request.try_read() { remaining_requests.remove(i); return Some((orig_index, match request { FirstRequest(..) => FirstResponse(response), SecondRequest(..) => SecondResponse(response), })); } } None } if let Some(i, response) = next_available() { match response { FirstResponse(response) => { send_second_request(response.data); }, SecondResponse(response) { result[i] = response.data; }, } }
It doesn't scale very well:
Alright. Thanks for a nice discussion!
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
You mean something like this?
It doesn't scale very well:
Alright. Thanks for a nice discussion!