use crate::role::a::RoleA;
use crate::role::Role;
use crossbeam_channel::{bounded, Sender};
#[derive(Debug)]
pub struct RoleADual<R>
where
R: Role,
R::Dual: Role,
{
#[doc(hidden)]
pub sender: Sender<R::Dual>,
}
impl<R: Role> Role for RoleADual<R> {
type Dual = RoleA<R::Dual>;
fn new() -> (Self, Self::Dual) {
let (sender_normal, _) = bounded::<R>(1);
let (sender_dual, _) = bounded::<R::Dual>(1);
(
RoleADual {
sender: sender_dual,
},
RoleA {
sender: sender_normal,
},
)
}
fn head_str() -> String {
"RoleADual".to_string()
}
fn tail_str() -> String {
format!("{}<{}>", R::head_str(), R::tail_str())
}
fn self_head_str(&self) -> String {
"RoleADual".to_string()
}
fn self_tail_str(&self) -> String {
format!("{}<{}>", R::head_str(), R::tail_str())
}
}
impl<R: Role> RoleADual<R> {
pub fn continuation(&self) -> R {
let (here, there) = R::new();
self.sender.send(there).unwrap_or(());
here
}
}