use std::error::Error;
use mpstthree::binary::struct_trait::{end::End, recv::Recv, send::Send};
use mpstthree::meshedchannels::MeshedChannels;
use mpstthree::role::a::RoleA;
use mpstthree::role::b::RoleB;
use mpstthree::role::c::RoleC;
use mpstthree::role::end::RoleEnd;
use mpstthree::name::a::NameA;
use mpstthree::name::b::NameB;
use mpstthree::name::c::NameC;
use mpstthree::functionmpst::fork::fork_mpst;
type AtoB = Send<i32, End>;
type AtoC = Recv<i32, End>;
type BtoA = Recv<i32, End>;
type BtoC = Send<i32, End>;
type CtoA = Send<i32, End>;
type CtoB = Recv<i32, End>;
type StackA = RoleB<RoleC<RoleEnd>>;
type StackB = RoleA<RoleC<RoleEnd>>;
type StackC = RoleA<RoleB<RoleEnd>>;
type EndpointA = MeshedChannels<AtoB, AtoC, StackA, NameA>;
type EndpointB = MeshedChannels<BtoA, BtoC, StackB, NameB>;
type EndpointC = MeshedChannels<CtoA, CtoB, StackC, NameC>;
fn endpoint_a(s: EndpointA) -> Result<(), Box<dyn Error>> {
let s = s.send(1);
let (_x, s) = s.recv()?;
s.close()
}
fn endpoint_b(s: EndpointB) -> Result<(), Box<dyn Error>> {
let (_x, s) = s.recv()?;
let s = s.send(2);
s.close()
}
fn endpoint_c(s: EndpointC) -> Result<(), Box<dyn Error>> {
let s = s.send(3);
let (_x, s) = s.recv()?;
s.close()
}
fn main() {
let (thread_a, thread_b, thread_c) = fork_mpst(endpoint_a, endpoint_b, endpoint_c);
thread_a.join().unwrap();
thread_b.join().unwrap();
thread_c.join().unwrap();
println!("Done");
}