behavior_actors/atomic/worker/
roster.rs1use crate::atomic::OrderedRoles;
2
3use super::{PreparedWorker, WorkerSubmission};
4
5pub struct InitialWorkerRejection<Factory, Role, Worker, Plan, Rejection> {
7 pub factory: Factory,
9 pub prepared: Vec<PreparedWorker<Role, Worker, Plan>>,
11 pub role: Role,
13 pub reason: Rejection,
15 pub remaining: Vec<Role>,
17}
18
19pub(in crate::atomic) fn prepare_initial_workers<Factory, Role, Worker, Plan, Rejection>(
20 mut factory: Factory,
21 roles: OrderedRoles<Role>,
22) -> Result<
23 Vec<PreparedWorker<Role, Worker, Plan>>,
24 InitialWorkerRejection<Factory, Role, Worker, Plan, Rejection>,
25>
26where
27 Factory: FnMut(&Role) -> Result<WorkerSubmission<Worker, Plan>, Rejection>,
28{
29 let mut remaining_roles = roles.into_roles().into_iter();
30 let mut prepared = Vec::new();
31 for role in remaining_roles.by_ref() {
32 match factory(&role) {
33 Ok(submission) => prepared.push(PreparedWorker { role, submission }),
34 Err(rejection) => {
35 return Err(InitialWorkerRejection {
36 factory,
37 prepared,
38 role,
39 reason: rejection,
40 remaining: remaining_roles.collect(),
41 });
42 }
43 }
44 }
45 Ok(prepared)
46}