#![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); // 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>; // A enum Branching0fromFtoA { More( MeshedChannels< RS, RS, RS, RS, Recv<(), Send<(), RecursAtoF>>, R2F>>>>>, NameA, >, ), Done(MeshedChannels), } type RecursAtoF = Recv; // B enum Branching0fromFtoB { More( MeshedChannels< SR, RS, RS, RS, Recv<(), Send<(), RecursBtoF>>, R2F>>>>>, NameB, >, ), Done(MeshedChannels), } type RecursBtoF = Recv; // C enum Branching0fromFtoC { More( MeshedChannels< SR, SR, RS, RS, Recv<(), Send<(), RecursCtoF>>, R2F>>>>>, NameC, >, ), Done(MeshedChannels), } type RecursCtoF = Recv; // D enum Branching0fromFtoD { More( MeshedChannels< SR, SR, SR, RS, Recv<(), Send<(), RecursDtoF>>, R2F>>>>>, NameD, >, ), Done(MeshedChannels), } type RecursDtoF = Recv; // E enum Branching0fromFtoE { More( MeshedChannels< SR, SR, SR, SR, Recv<(), Send<(), RecursEtoF>>, R2F>>>>>, NameE, >, ), Done(MeshedChannels), } type RecursEtoF = Recv; // F type Choose0fromFtoA = Send; type Choose0fromFtoB = Send; type Choose0fromFtoC = Send; type Choose0fromFtoD = Send; type Choose0fromFtoE = Send; type EndpointMoreF = MeshedChannels< Send<(), Recv<(), Choose0fromFtoA>>, Send<(), Recv<(), Choose0fromFtoB>>, Send<(), Recv<(), Choose0fromFtoC>>, Send<(), Recv<(), Choose0fromFtoD>>, Send<(), Recv<(), Choose0fromFtoE>>, R2A>>>>, NameF, >; // 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< Choose0fromFtoA, Choose0fromFtoB, Choose0fromFtoC, Choose0fromFtoD, Choose0fromFtoE, RoleBroadcast, NameF, >; fn endpoint_a(s: EndpointA) -> Result<(), Box> { offer_mpst!(s, { Branching0fromFtoA::Done(s) => { s.close() }, Branching0fromFtoA::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(()); endpoint_a(s) }, }) } fn endpoint_b(s: EndpointB) -> Result<(), Box> { offer_mpst!(s, { Branching0fromFtoB::Done(s) => { s.close() }, Branching0fromFtoB::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(()); endpoint_b(s) }, }) } fn endpoint_c(s: EndpointC) -> Result<(), Box> { offer_mpst!(s, { Branching0fromFtoC::Done(s) => { s.close() }, Branching0fromFtoC::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(()); endpoint_c(s) }, }) } fn endpoint_d(s: EndpointD) -> Result<(), Box> { offer_mpst!(s, { Branching0fromFtoD::Done(s) => { s.close() }, Branching0fromFtoD::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(()); endpoint_d(s) }, }) } fn endpoint_e(s: EndpointE) -> Result<(), Box> { offer_mpst!(s, { Branching0fromFtoE::Done(s) => { s.close() }, Branching0fromFtoE::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(); endpoint_e(s) }, }) } fn endpoint_f(s: EndpointF) -> Result<(), Box> { recurs_f(s, LOOPS) } fn recurs_f(s: EndpointF, index: i64) -> Result<(), Box> { match index { 0 => { let s = choose_mpst_f_to_all!( s, Branching0fromFtoA::Done, Branching0fromFtoB::Done, Branching0fromFtoC::Done, Branching0fromFtoD::Done, Branching0fromFtoE::Done ); s.close() } i => { let s: EndpointMoreF = choose_mpst_f_to_all!( s, Branching0fromFtoA::More, Branching0fromFtoB::More, Branching0fromFtoC::More, Branching0fromFtoD::More, Branching0fromFtoE::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(); recurs_f(s, i - 1) } } } fn main() { let (thread_a, thread_b, thread_c, thread_d, thread_e, thread_f) = fork_mpst( endpoint_a, endpoint_b, endpoint_c, endpoint_d, endpoint_e, endpoint_f, ); thread_a.join().unwrap(); thread_b.join().unwrap(); thread_c.join().unwrap(); thread_d.join().unwrap(); thread_e.join().unwrap(); thread_f.join().unwrap(); }