#![allow( clippy::type_complexity, clippy::too_many_arguments, clippy::large_enum_variant )] use mpstthree::binary::struct_trait::{end::End, recv::Recv, send::Send}; use mpstthree::generate; use mpstthree::role::broadcast::RoleBroadcast; use mpstthree::role::end::RoleEnd; use std::error::Error; static LOOPS: i64 = 100; // Create new roles generate!("recursive", MeshedChannels, A, B, C, D, E, F, G, H, I, J, K); // Types // Send/Recv type RS = Recv<(), Send<(), End>>; type SR = Send<(), Recv<(), End>>; // Roles type R2A = RoleA>; type R2B = RoleB>; type R2C = RoleC>; type R2D = RoleD>; type R2E = RoleE>; type R2F = RoleF>; type R2G = RoleG>; type R2H = RoleH>; type R2I = RoleI>; type R2J = RoleJ>; type R2K = RoleK>; // A enum Branching0fromKtoA { More( MeshedChannels< RS, RS, RS, RS, RS, RS, RS, RS, RS, Recv<(), Send<(), RecursAtoK>>, R2K>>>>>>>>>>, NameA, >, ), Done(MeshedChannels), } type RecursAtoK = Recv; // B enum Branching0fromKtoB { More( MeshedChannels< SR, RS, RS, RS, RS, RS, RS, RS, RS, Recv<(), Send<(), RecursBtoK>>, R2K>>>>>>>>>>, NameB, >, ), Done(MeshedChannels), } type RecursBtoK = Recv; // C enum Branching0fromKtoC { More( MeshedChannels< SR, SR, RS, RS, RS, RS, RS, RS, RS, Recv<(), Send<(), RecursCtoK>>, R2K>>>>>>>>>>, NameC, >, ), Done(MeshedChannels), } type RecursCtoK = Recv; // D enum Branching0fromKtoD { More( MeshedChannels< SR, SR, SR, RS, RS, RS, RS, RS, RS, Recv<(), Send<(), RecursDtoK>>, R2K>>>>>>>>>>, NameD, >, ), Done(MeshedChannels), } type RecursDtoK = Recv; // E enum Branching0fromKtoE { More( MeshedChannels< SR, SR, SR, SR, RS, RS, RS, RS, RS, Recv<(), Send<(), RecursEtoK>>, R2K>>>>>>>>>>, NameE, >, ), Done(MeshedChannels), } type RecursEtoK = Recv; // F enum Branching0fromKtoF { More( MeshedChannels< SR, SR, SR, SR, SR, RS, RS, RS, RS, Recv<(), Send<(), RecursFtoK>>, R2K>>>>>>>>>>, NameF, >, ), Done(MeshedChannels), } type RecursFtoK = Recv; // G enum Branching0fromKtoG { More( MeshedChannels< SR, SR, SR, SR, SR, SR, RS, RS, RS, Recv<(), Send<(), RecursGtoK>>, R2K>>>>>>>>>>, NameG, >, ), Done(MeshedChannels), } type RecursGtoK = Recv; // H enum Branching0fromKtoH { More( MeshedChannels< SR, SR, SR, SR, SR, SR, SR, RS, RS, Recv<(), Send<(), RecursHtoK>>, R2K>>>>>>>>>>, NameH, >, ), Done(MeshedChannels), } type RecursHtoK = Recv; // I enum Branching0fromKtoI { More( MeshedChannels< SR, SR, SR, SR, SR, SR, SR, SR, RS, Recv<(), Send<(), RecursItoK>>, R2K>>>>>>>>>>, NameI, >, ), Done(MeshedChannels), } type RecursItoK = Recv; // J enum Branching0fromKtoJ { More( MeshedChannels< SR, SR, SR, SR, SR, SR, SR, SR, SR, Recv<(), Send<(), RecursJtoK>>, R2K>>>>>>>>>>, NameJ, >, ), Done(MeshedChannels), } type RecursJtoK = Recv; // K type Choose0fromKtoA = Send; type Choose0fromKtoB = Send; type Choose0fromKtoC = Send; type Choose0fromKtoD = Send; type Choose0fromKtoE = Send; type Choose0fromKtoF = Send; type Choose0fromKtoG = Send; type Choose0fromKtoH = Send; type Choose0fromKtoI = Send; type Choose0fromKtoJ = Send; type EndpointMoreK = MeshedChannels< Send<(), Recv<(), Choose0fromKtoA>>, Send<(), Recv<(), Choose0fromKtoB>>, Send<(), Recv<(), Choose0fromKtoC>>, Send<(), Recv<(), Choose0fromKtoD>>, Send<(), Recv<(), Choose0fromKtoE>>, Send<(), Recv<(), Choose0fromKtoF>>, Send<(), Recv<(), Choose0fromKtoG>>, Send<(), Recv<(), Choose0fromKtoH>>, Send<(), Recv<(), Choose0fromKtoI>>, Send<(), Recv<(), Choose0fromKtoJ>>, R2A>>>>>>>>>, NameK, >; // Creating the MP sessions type EndpointA = MeshedChannels, NameA>; type EndpointB = MeshedChannels, NameB>; type EndpointC = MeshedChannels, NameC>; type EndpointD = MeshedChannels, NameD>; type EndpointE = MeshedChannels, NameE>; type EndpointF = MeshedChannels, NameF>; type EndpointG = MeshedChannels, NameG>; type EndpointH = MeshedChannels, NameH>; type EndpointI = MeshedChannels, NameI>; type EndpointJ = MeshedChannels, NameJ>; type EndpointK = MeshedChannels< Choose0fromKtoA, Choose0fromKtoB, Choose0fromKtoC, Choose0fromKtoD, Choose0fromKtoE, Choose0fromKtoF, Choose0fromKtoG, Choose0fromKtoH, Choose0fromKtoI, Choose0fromKtoJ, RoleBroadcast, NameK, >; fn endpoint_a(s: EndpointA) -> Result<(), Box> { offer_mpst!(s, { Branching0fromKtoA::Done(s) => { s.close() }, Branching0fromKtoA::More(s) => { let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); endpoint_a(s) }, }) } fn endpoint_b(s: EndpointB) -> Result<(), Box> { offer_mpst!(s, { Branching0fromKtoB::Done(s) => { s.close() }, Branching0fromKtoB::More(s) => { let (_, s) = s.recv(); let s = s.send(()); let s = s.send(()); let (_, s) = s.recv(); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); endpoint_b(s) }, }) } fn endpoint_c(s: EndpointC) -> Result<(), Box> { offer_mpst!(s, { Branching0fromKtoC::Done(s) => { s.close() }, Branching0fromKtoC::More(s) => { let (_, s) = s.recv(); let s = s.send(()); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); endpoint_c(s) }, }) } fn endpoint_d(s: EndpointD) -> Result<(), Box> { offer_mpst!(s, { Branching0fromKtoD::Done(s) => { s.close() }, Branching0fromKtoD::More(s) => { let (_, s) = s.recv(); let s = s.send(()); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); endpoint_d(s) }, }) } fn endpoint_e(s: EndpointE) -> Result<(), Box> { offer_mpst!(s, { Branching0fromKtoE::Done(s) => { s.close() }, Branching0fromKtoE::More(s) => { let (_, s) = s.recv(); let s = s.send(()); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); endpoint_e(s) }, }) } fn endpoint_f(s: EndpointF) -> Result<(), Box> { offer_mpst!(s, { Branching0fromKtoF::Done(s) => { s.close() }, Branching0fromKtoF::More(s) => { let (_, s) = s.recv(); let s = s.send(()); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); endpoint_f(s) }, }) } fn endpoint_g(s: EndpointG) -> Result<(), Box> { offer_mpst!(s, { Branching0fromKtoG::Done(s) => { s.close() }, Branching0fromKtoG::More(s) => { let (_, s) = s.recv(); let s = s.send(()); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); endpoint_g(s) }, }) } fn endpoint_h(s: EndpointH) -> Result<(), Box> { offer_mpst!(s, { Branching0fromKtoH::Done(s) => { s.close() }, Branching0fromKtoH::More(s) => { let (_, s) = s.recv(); let s = s.send(()); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); endpoint_h(s) }, }) } fn endpoint_i(s: EndpointI) -> Result<(), Box> { offer_mpst!(s, { Branching0fromKtoI::Done(s) => { s.close() }, Branching0fromKtoI::More(s) => { let (_, s) = s.recv(); let s = s.send(()); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let (_, s) = s.recv(); let s = s.send(()); endpoint_i(s) }, }) } fn endpoint_j(s: EndpointJ) -> Result<(), Box> { offer_mpst!(s, { Branching0fromKtoJ::Done(s) => { s.close() }, Branching0fromKtoJ::More(s) => { let (_, s) = s.recv(); let s = s.send(()); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); endpoint_j(s) }, }) } fn endpoint_k(s: EndpointK) -> Result<(), Box> { recurs_k(s, LOOPS) } fn recurs_k(s: EndpointK, index: i64) -> Result<(), Box> { match index { 0 => { let s = choose_mpst_k_to_all!( s, Branching0fromKtoA::Done, Branching0fromKtoB::Done, Branching0fromKtoC::Done, Branching0fromKtoD::Done, Branching0fromKtoE::Done, Branching0fromKtoF::Done, Branching0fromKtoG::Done, Branching0fromKtoH::Done, Branching0fromKtoI::Done, Branching0fromKtoJ::Done ); s.close() } i => { let s: EndpointMoreK = choose_mpst_k_to_all!( s, Branching0fromKtoA::More, Branching0fromKtoB::More, Branching0fromKtoC::More, Branching0fromKtoD::More, Branching0fromKtoE::More, Branching0fromKtoF::More, Branching0fromKtoG::More, Branching0fromKtoH::More, Branching0fromKtoI::More, Branching0fromKtoJ::More ); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); let s = s.send(()); let (_, s) = s.recv(); recurs_k(s, i - 1) } } } fn main() { let ( thread_a, thread_b, thread_c, thread_d, thread_e, thread_f, thread_g, thread_h, thread_i, thread_j, thread_k, ) = fork_mpst( endpoint_a, endpoint_b, endpoint_c, endpoint_d, endpoint_e, endpoint_f, endpoint_g, endpoint_h, endpoint_i, endpoint_j, endpoint_k, ); thread_a.join().unwrap(); thread_b.join().unwrap(); thread_c.join().unwrap(); thread_d.join().unwrap(); thread_e.join().unwrap(); thread_f.join().unwrap(); thread_g.join().unwrap(); thread_h.join().unwrap(); thread_i.join().unwrap(); thread_j.join().unwrap(); thread_k.join().unwrap(); }