1use crate::role::b_dual::RoleBDual;
6use crate::role::Role;
7use crossbeam_channel::{bounded, Sender};
8
9#[derive(Debug)]
30pub struct RoleB<R>
31where
32 R: Role,
33 R::Dual: Role,
34{
35 #[doc(hidden)]
36 pub sender: Sender<R::Dual>,
37}
38
39impl<R: Role> Role for RoleB<R> {
40 type Dual = RoleBDual<R::Dual>;
41
42 fn new() -> (Self, Self::Dual) {
43 let (sender_normal, _) = bounded::<R>(1);
44 let (sender_dual, _) = bounded::<R::Dual>(1);
45
46 (
47 RoleB {
48 sender: sender_dual,
49 },
50 RoleBDual {
51 sender: sender_normal,
52 },
53 )
54 }
55
56 fn head_str() -> String {
57 "RoleB".to_string()
58 }
59
60 fn tail_str() -> String {
61 format!("{}<{}>", R::head_str(), R::tail_str())
62 }
63
64 fn self_head_str(&self) -> String {
65 "RoleB".to_string()
66 }
67
68 fn self_tail_str(&self) -> String {
69 format!("{}<{}>", R::head_str(), R::tail_str())
70 }
71}
72
73impl<R: Role> RoleB<R> {
74 pub fn continuation(&self) -> R {
76 let (here, there) = R::new();
77 self.sender.send(there).unwrap_or(());
78 here
79 }
80}