#[macro_export]
#[cfg_attr(doc_cfg, doc(cfg(feature = "macros_simple")))]
macro_rules! create_normal_role {
($role_name:ident, $dual_name:ident) => {
#[derive(Debug)]
struct $role_name<R>
where
R: mpstthree::role::Role,
R::Dual: mpstthree::role::Role,
{
#[doc(hidden)]
sender: crossbeam_channel::Sender<R::Dual>,
}
#[derive(Debug)]
struct $dual_name<R>
where
R: mpstthree::role::Role,
R::Dual: mpstthree::role::Role,
{
sender: crossbeam_channel::Sender<R::Dual>,
}
impl<R: mpstthree::role::Role> mpstthree::role::Role for $role_name<R> {
type Dual = $dual_name<<R as mpstthree::role::Role>::Dual>;
#[doc(hidden)]
fn new() -> (Self, Self::Dual) {
let (sender_normal, _) = crossbeam_channel::bounded::<R>(1);
let (sender_dual, _) = crossbeam_channel::bounded::<R::Dual>(1);
(
$role_name {
sender: sender_dual,
},
$dual_name {
sender: sender_normal,
},
)
}
#[doc(hidden)]
fn head_str() -> String {
String::from(stringify!($role_name))
}
#[doc(hidden)]
fn tail_str() -> String {
format!(
"{}<{}>",
<R as mpstthree::role::Role>::head_str(),
<R as mpstthree::role::Role>::tail_str()
)
}
#[doc(hidden)]
fn self_head_str(&self) -> String {
String::from(stringify!($role_name))
}
#[doc(hidden)]
fn self_tail_str(&self) -> String {
format!(
"{}<{}>",
<R as mpstthree::role::Role>::head_str(),
<R as mpstthree::role::Role>::tail_str()
)
}
}
impl<R: mpstthree::role::Role> mpstthree::role::Role for $dual_name<R> {
type Dual = $role_name<<R as mpstthree::role::Role>::Dual>;
#[doc(hidden)]
fn new() -> (Self, Self::Dual) {
let (sender_normal, _) = crossbeam_channel::bounded::<R>(1);
let (sender_dual, _) = crossbeam_channel::bounded::<R::Dual>(1);
(
$dual_name {
sender: sender_dual,
},
$role_name {
sender: sender_normal,
},
)
}
#[doc(hidden)]
fn head_str() -> String {
String::from(stringify!($dual_name))
}
#[doc(hidden)]
fn tail_str() -> String {
format!(
"{}<{}>",
<R as mpstthree::role::Role>::head_str(),
<R as mpstthree::role::Role>::tail_str()
)
}
#[doc(hidden)]
fn self_head_str(&self) -> String {
String::from(stringify!($dual_name))
}
#[doc(hidden)]
fn self_tail_str(&self) -> String {
format!(
"{}<{}>",
<R as mpstthree::role::Role>::head_str(),
<R as mpstthree::role::Role>::tail_str()
)
}
}
impl<R: mpstthree::role::Role> $role_name<R> {
pub fn continuation(&self) -> R {
let (here, there) = R::new();
self.sender.send(there).unwrap_or(());
here
}
}
impl<R: mpstthree::role::Role> $dual_name<R> {
pub fn continuation(&self) -> R {
let (here, there) = R::new();
self.sender.send(there).unwrap_or(());
here
}
}
};
}
#[macro_export]
#[cfg_attr(doc_cfg, doc(cfg(feature = "macros_simple")))]
macro_rules! create_multiple_normal_role {
($( $role_name: ident, $dual_name: ident | )+ ) => {
$(mpstthree::create_normal_role!($role_name, $dual_name);)+
}
}
#[macro_export]
#[cfg_attr(doc_cfg, doc(cfg(feature = "macros_simple")))]
macro_rules! create_broadcast_role {
($role_name:ident, $dual_name:ident) => {
#[derive(Debug)]
struct $role_name<R1, R2>
where
R1: mpstthree::role::Role,
R2: mpstthree::role::Role,
R1::Dual: mpstthree::role::Role,
R2::Dual: mpstthree::role::Role,
{
sender1: crossbeam_channel::Sender<R1::Dual>,
sender2: crossbeam_channel::Sender<R2::Dual>,
}
#[derive(Debug)]
struct $dual_name<R1, R2>
where
R1: mpstthree::role::Role,
R2: mpstthree::role::Role,
R1::Dual: mpstthree::role::Role,
R2::Dual: mpstthree::role::Role,
{
sender1: crossbeam_channel::Sender<R1::Dual>,
sender2: crossbeam_channel::Sender<R2::Dual>,
}
impl<R1: mpstthree::role::Role, R2: mpstthree::role::Role> mpstthree::role::Role
for $role_name<R1, R2>
{
type Dual = $dual_name<
<R1 as mpstthree::role::Role>::Dual,
<R2 as mpstthree::role::Role>::Dual,
>;
#[doc(hidden)]
fn new() -> (Self, Self::Dual) {
let (sender_normal_1, _) = crossbeam_channel::bounded::<R1>(1);
let (sender_normal_2, _) = crossbeam_channel::bounded::<R2>(1);
let (sender_dual_1, _) = crossbeam_channel::bounded::<R1::Dual>(1);
let (sender_dual_2, _) = crossbeam_channel::bounded::<R2::Dual>(1);
(
$role_name {
sender1: sender_dual_1,
sender2: sender_dual_2,
},
$dual_name {
sender1: sender_normal_1,
sender2: sender_normal_2,
},
)
}
#[doc(hidden)]
fn head_str() -> String {
String::from(stringify!($role_name))
}
#[doc(hidden)]
fn tail_str() -> String {
format!(
"{}<{}> + {}<{}>",
<R1 as mpstthree::role::Role>::head_str(),
<R1 as mpstthree::role::Role>::tail_str(),
<R2 as mpstthree::role::Role>::head_str(),
<R2 as mpstthree::role::Role>::tail_str()
)
}
#[doc(hidden)]
fn self_head_str(&self) -> String {
String::from(stringify!($role_name))
}
#[doc(hidden)]
fn self_tail_str(&self) -> String {
format!(
"{}<{}> + {}<{}>",
<R1 as mpstthree::role::Role>::head_str(),
<R1 as mpstthree::role::Role>::tail_str(),
<R2 as mpstthree::role::Role>::head_str(),
<R2 as mpstthree::role::Role>::tail_str()
)
}
}
impl<R1: mpstthree::role::Role, R2: mpstthree::role::Role> mpstthree::role::Role
for $dual_name<R1, R2>
{
type Dual = $role_name<
<R1 as mpstthree::role::Role>::Dual,
<R2 as mpstthree::role::Role>::Dual,
>;
#[doc(hidden)]
fn new() -> (Self, Self::Dual) {
let (sender_normal_1, _) = crossbeam_channel::bounded::<R1>(1);
let (sender_normal_2, _) = crossbeam_channel::bounded::<R2>(1);
let (sender_dual_1, _) = crossbeam_channel::bounded::<R1::Dual>(1);
let (sender_dual_2, _) = crossbeam_channel::bounded::<R2::Dual>(1);
(
$dual_name {
sender1: sender_dual_1,
sender2: sender_dual_2,
},
$role_name {
sender1: sender_normal_1,
sender2: sender_normal_2,
},
)
}
#[doc(hidden)]
fn head_str() -> String {
String::from(stringify!($dual_name))
}
#[doc(hidden)]
fn tail_str() -> String {
format!(
"{}<{}> + {}<{}>",
<R1 as mpstthree::role::Role>::head_str(),
<R1 as mpstthree::role::Role>::tail_str(),
<R2 as mpstthree::role::Role>::head_str(),
<R2 as mpstthree::role::Role>::tail_str()
)
}
#[doc(hidden)]
fn self_head_str(&self) -> String {
String::from(stringify!($dual_name))
}
#[doc(hidden)]
fn self_tail_str(&self) -> String {
format!(
"{}<{}> + {}<{}>",
<R1 as mpstthree::role::Role>::head_str(),
<R1 as mpstthree::role::Role>::tail_str(),
<R2 as mpstthree::role::Role>::head_str(),
<R2 as mpstthree::role::Role>::tail_str()
)
}
}
impl<R1: mpstthree::role::Role, R2: mpstthree::role::Role> $role_name<R1, R2> {
pub fn continuation_left(&self) -> R1 {
let (here, there) = R1::new();
self.sender1.send(there).unwrap_or(());
here
}
pub fn continuation_right(&self) -> R2 {
let (here, there) = R2::new();
self.sender2.send(there).unwrap_or(());
here
}
}
impl<R1: mpstthree::role::Role, R2: mpstthree::role::Role> $dual_name<R1, R2> {
pub fn continuation_left(&self) -> R1 {
let (here, there) = R1::new();
self.sender1.send(there).unwrap_or(());
here
}
pub fn continuation_right(&self) -> R2 {
let (here, there) = R2::new();
self.sender2.send(there).unwrap_or(());
here
}
}
};
}
#[macro_export]
#[cfg_attr(doc_cfg, doc(cfg(feature = "macros_simple")))]
macro_rules! create_multiple_broadcast_role {
($( $role_name: ident, $dual_name: ident | )+ ) => {
$(
mpstthree::create_broadcast_role!($role_name, $dual_name);
)+
}
}
#[macro_export]
#[cfg_attr(doc_cfg, doc(cfg(feature = "macros_simple")))]
macro_rules! create_normal_role_short {
($role_name:ident) => {
mpst_seq_proc::create_normal_role_short!($role_name);
};
}
#[macro_export]
#[cfg_attr(doc_cfg, doc(cfg(feature = "macros_simple")))]
macro_rules! create_multiple_normal_role_short {
($( $role_name: ident),+ $(,)? ) => {
$(
mpstthree::create_normal_role_short!($role_name);
)+
}
}
#[macro_export]
#[cfg_attr(doc_cfg, doc(cfg(feature = "macros_simple")))]
macro_rules! create_broadcast_role_short {
($role_name:ident) => {
mpst_seq_proc::create_broadcast_role_short!($role_name);
};
}
#[macro_export]
#[cfg_attr(doc_cfg, doc(cfg(feature = "macros_simple")))]
macro_rules! create_multiple_broadcast_role_short {
($( $role_name: ident),+ $(,)? ) => {
$(
mpstthree::create_broadcast_role_short!($role_name);
)+
}
}