#![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 // A enum Branching0fromKtoA { Forward( MeshedChannels< Send<(), End>, End, End, End, End, End, End, End, End, RecursAtoK, RoleB>, NameA, >, ), Backward( MeshedChannels< Recv<(), End>, End, End, End, End, End, End, End, End, RecursAtoK, RoleB>, NameA, >, ), Done(MeshedChannels), } type RecursAtoK = Recv; // B enum Branching0fromKtoB { Forward( MeshedChannels< Recv<(), End>, Send<(), End>, End, End, End, End, End, End, End, RecursBtoK, RoleA>>, NameB, >, ), Backward( MeshedChannels< Send<(), End>, Recv<(), End>, End, End, End, End, End, End, End, RecursBtoK, RoleC>>, NameB, >, ), Done(MeshedChannels), } type RecursBtoK = Recv; // C enum Branching0fromKtoC { Forward( MeshedChannels< End, Recv<(), End>, Send<(), End>, End, End, End, End, End, End, RecursCtoK, RoleB>>, NameC, >, ), Backward( MeshedChannels< End, Send<(), End>, Recv<(), End>, End, End, End, End, End, End, RecursCtoK, RoleD>>, NameC, >, ), Done(MeshedChannels), } type RecursCtoK = Recv; // D enum Branching0fromKtoD { Forward( MeshedChannels< End, End, Recv<(), End>, Send<(), End>, End, End, End, End, End, RecursDtoK, RoleC>>, NameD, >, ), Backward( MeshedChannels< End, End, Send<(), End>, Recv<(), End>, End, End, End, End, End, RecursDtoK, RoleE>>, NameD, >, ), Done(MeshedChannels), } type RecursDtoK = Recv; // E enum Branching0fromKtoE { Forward( MeshedChannels< End, End, End, Recv<(), End>, Send<(), End>, End, End, End, End, RecursEtoK, RoleD>>, NameE, >, ), Backward( MeshedChannels< End, End, End, Send<(), End>, Recv<(), End>, End, End, End, End, RecursEtoK, RoleF>>, NameE, >, ), Done(MeshedChannels), } type RecursEtoK = Recv; // F enum Branching0fromKtoF { Forward( MeshedChannels< End, End, End, End, Recv<(), End>, Send<(), End>, End, End, End, RecursFtoK, RoleE>>, NameF, >, ), Backward( MeshedChannels< End, End, End, End, Send<(), End>, Recv<(), End>, End, End, End, RecursFtoK, RoleG>>, NameF, >, ), Done(MeshedChannels), } type RecursFtoK = Recv; // G enum Branching0fromKtoG { Forward( MeshedChannels< End, End, End, End, End, Recv<(), End>, Send<(), End>, End, End, RecursGtoK, RoleF>>, NameG, >, ), Backward( MeshedChannels< End, End, End, End, End, Send<(), End>, Recv<(), End>, End, End, RecursGtoK, RoleH>>, NameG, >, ), Done(MeshedChannels), } type RecursGtoK = Recv; // H enum Branching0fromKtoH { Forward( MeshedChannels< End, End, End, End, End, End, Recv<(), End>, Send<(), End>, End, RecursHtoK, RoleG>>, NameH, >, ), Backward( MeshedChannels< End, End, End, End, End, End, Send<(), End>, Recv<(), End>, End, RecursHtoK, RoleI>>, NameH, >, ), Done(MeshedChannels), } type RecursHtoK = Recv; // I enum Branching0fromKtoI { Forward( MeshedChannels< End, End, End, End, End, End, End, Recv<(), End>, Send<(), End>, RecursItoK, RoleH>>, NameI, >, ), Backward( MeshedChannels< End, End, End, End, End, End, End, Send<(), End>, Recv<(), End>, RecursItoK, RoleJ>>, NameI, >, ), Done(MeshedChannels), } type RecursItoK = Recv; // J enum Branching0fromKtoJ { Forward( MeshedChannels< End, End, End, End, End, End, End, End, Recv<(), End>, Send<(), RecursJtoK>, RoleI>>, NameJ, >, ), Backward( MeshedChannels< End, End, End, End, End, End, End, End, Send<(), End>, Recv<(), RecursJtoK>, RoleK>>, 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 EndpointForwardK = MeshedChannels< Choose0fromKtoA, Choose0fromKtoB, Choose0fromKtoC, Choose0fromKtoD, Choose0fromKtoE, Choose0fromKtoF, Choose0fromKtoG, Choose0fromKtoH, Choose0fromKtoI, Recv<(), Choose0fromKtoJ>, RoleJ, NameK, >; type EndpointBackwardK = MeshedChannels< Choose0fromKtoA, Choose0fromKtoB, Choose0fromKtoC, Choose0fromKtoD, Choose0fromKtoE, Choose0fromKtoF, Choose0fromKtoG, Choose0fromKtoH, Choose0fromKtoI, Send<(), Choose0fromKtoJ>, RoleJ, 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::Forward(s) => { let s = s.send(()); endpoint_a(s) }, Branching0fromKtoA::Backward(s) => { let (_, s) = s.recv(); endpoint_a(s) }, }) } fn endpoint_b(s: EndpointB) -> Result<(), Box> { offer_mpst!(s, { Branching0fromKtoB::Done(s) => { s.close() }, Branching0fromKtoB::Forward(s) => { let ((), s) = s.recv(); let s = s.send(()); endpoint_b(s) }, Branching0fromKtoB::Backward(s) => { 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::Forward(s) => { let ((), s) = s.recv(); let s = s.send(()); endpoint_c(s) }, Branching0fromKtoC::Backward(s) => { 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::Forward(s) => { let ((), s) = s.recv(); let s = s.send(()); endpoint_d(s) }, Branching0fromKtoD::Backward(s) => { 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::Forward(s) => { let ((), s) = s.recv(); let s = s.send(()); endpoint_e(s) }, Branching0fromKtoE::Backward(s) => { 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::Forward(s) => { let ((), s) = s.recv(); let s = s.send(()); endpoint_f(s) }, Branching0fromKtoF::Backward(s) => { 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::Forward(s) => { let ((), s) = s.recv(); let s = s.send(()); endpoint_g(s) }, Branching0fromKtoG::Backward(s) => { 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::Forward(s) => { let ((), s) = s.recv(); let s = s.send(()); endpoint_h(s) }, Branching0fromKtoH::Backward(s) => { 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::Forward(s) => { let ((), s) = s.recv(); let s = s.send(()); endpoint_i(s) }, Branching0fromKtoI::Backward(s) => { 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::Forward(s) => { let ((), s) = s.recv(); let s = s.send(()); endpoint_j(s) }, Branching0fromKtoJ::Backward(s) => { let ((), s) = s.recv(); let s = s.send(()); 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 if i % 2 == 0 => { let s: EndpointForwardK = choose_mpst_k_to_all!( s, Branching0fromKtoA::Forward, Branching0fromKtoB::Forward, Branching0fromKtoC::Forward, Branching0fromKtoD::Forward, Branching0fromKtoE::Forward, Branching0fromKtoF::Forward, Branching0fromKtoG::Forward, Branching0fromKtoH::Forward, Branching0fromKtoI::Forward, Branching0fromKtoJ::Forward ); let (_, s) = s.recv(); recurs_k(s, i - 1) } i => { let s: EndpointBackwardK = choose_mpst_k_to_all!( s, Branching0fromKtoA::Backward, Branching0fromKtoB::Backward, Branching0fromKtoC::Backward, Branching0fromKtoD::Backward, Branching0fromKtoE::Backward, Branching0fromKtoF::Backward, Branching0fromKtoG::Backward, Branching0fromKtoH::Backward, Branching0fromKtoI::Backward, Branching0fromKtoJ::Backward ); let s = s.send(()); 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(); }