gwr_components/
connect.rs1pub use paste::paste;
6
7#[macro_export]
8macro_rules! connect_port {
11 ($from:expr, $from_port_name:ident => $to:expr, $to_port_name:ident) => {
12 {
13 gwr_track::debug!($from.entity ; "Connect {}.{} => {}.{}", $from, stringify!($from_port_name), $to, stringify!($to_port_name));
14 $crate::connect::paste! {
15 $from.[< connect_port_ $from_port_name >]($to.[< port_ $to_port_name >]())
16 }
17 }
18 };
19 ($from:expr, $from_port_name:ident, $from_index:expr => $to:expr, $to_port_name:ident) => {
20 {
21 let from_index: usize = $from_index;
22 gwr_track::debug!($from.entity ; "Connect {}.{}[{}] => {}.{}", $from, stringify!($from_port_name), from_index, $to, stringify!($to_port_name));
23 $crate::connect::paste! {
24 $from.[< connect_port_ $from_port_name _i >](from_index, $to.[< port_ $to_port_name >]())
25 }
26 }
27 };
28 ($from:expr, $from_port_name:ident => $to:expr, $to_port_name:ident, $to_index:expr) => {
29 {
30 let to_index: usize = $to_index;
31 gwr_track::debug!($from.entity ; "Connect {}.{} => {}.{}[{}]", $from, stringify!($from_port_name), $to, stringify!($to_port_name), to_index);
32 $crate::connect::paste! {
33 $from.[< connect_port_ $from_port_name >]($to.[< port_ $to_port_name _i >](to_index))
34 }
35 }
36 };
37 ($from:expr, $from_port_name:ident, $from_index:expr => $to:expr, $to_port_name:ident, $to_index:expr) => {
38 {
39 let from_index: usize = $from_index;
40 let to_index: usize = $to_index;
41 gwr_track::debug!($from.entity ; "Connect {}.{}[{}] => {}.{}[{}]", $from, stringify!($from_port_name), from_index, $to, stringify!($to_port_name), to_index);
42 $crate::connect::paste! {
43 $from.[< connect_port_ $from_port_name _i >](from_index, $to.[< port_ $to_port_name _i >](to_index))
44 }
45 }
46 };
47}
48
49#[macro_export]
50macro_rules! connect_tx {
54 ($component:expr, $fn:ident ; $port_state:ident) => {
55 $crate::connect::paste! {
56 $component
57 .borrow_mut()
58 .as_mut()
59 .unwrap()
60 .$fn($port_state)
61 }
62 };
63}
64
65#[macro_export]
66macro_rules! connect_tx_i {
70 ($component:expr, $fn:ident, $index:expr ; $port_state:ident) => {
71 $component
72 .borrow_mut()
73 .as_mut()
74 .unwrap()
75 .$fn($index, $port_state)
76 };
77}
78
79#[macro_export]
80macro_rules! port_rx {
84 ($component:expr, $fn:ident) => {
85 $component.borrow().as_ref().unwrap().$fn()
86 };
87}
88
89#[macro_export]
90macro_rules! port_rx_i {
94 ($component:expr, $fn:ident, $index:expr) => {
95 $component.borrow().as_ref().unwrap().$fn($index)
96 };
97}
98
99#[macro_export]
100macro_rules! borrow_option {
102 ($var:expr) => {
103 $var.borrow().as_ref().unwrap()
104 };
105}
106
107#[macro_export]
108macro_rules! borrow_option_mut {
110 ($var:expr) => {
111 $var.borrow_mut().as_mut().unwrap()
112 };
113}
114
115#[macro_export]
116macro_rules! take_option {
118 ($var:expr) => {
119 $var.borrow_mut().take().unwrap()
120 };
121}