lifeline/dyn_bus/
macros.rs1#[macro_export]
33macro_rules! lifeline_bus (
34 (struct $name:ident $(< $( $gen:ident ),+ >)? ) => {
35 lifeline_bus! { () struct $name $(< $( $gen ),+ >)? }
36 };
37
38 (pub struct $name:ident $(< $( $gen:ident ),+ >)* ) => {
39 lifeline_bus! { (pub) struct $name $(< $( $gen ),+ >)* }
40 };
41
42 (($($vis:tt)*) struct $name:ident $(< $( $gen:ident ),+ >)? ) => {
43 #[derive(Debug)]
44 #[allow(non_snake_case)]
45 $($vis)* struct $name $(< $( $gen: std::fmt::Debug ),+ >)? {
46 storage: $crate::dyn_bus::DynBusStorage<Self>,
47 $(
48 $( $gen: std::marker::PhantomData<$gen> ),+
49 )?
50 }
51
52 impl$(< $( $gen: std::fmt::Debug ),+ >)? std::default::Default for $name $(< $( $gen ),+ >)? {
53 fn default() -> Self {
54 Self {
55 storage: $crate::dyn_bus::DynBusStorage::default(),
56 $(
57 $( $gen: std::marker::PhantomData::<$gen> ),+
58 )?
59 }
60 }
61 }
62
63 impl$(< $( $gen: std::fmt::Debug ),+ >)? $crate::dyn_bus::DynBus for $name$(< $( $gen ),+ >)? {
64 fn store_rx<Msg>(&self, rx: <Msg::Channel as $crate::Channel>::Rx) -> Result<(), $crate::error::AlreadyLinkedError>
65 where Msg: $crate::Message<Self> + 'static
66 {
67 self.storage().store_channel::<Msg, Msg::Channel, Self>(Some(rx), None)
68 }
69
70 fn store_tx<Msg>(&self, tx: <Msg::Channel as $crate::Channel>::Tx) -> Result<(), $crate::error::AlreadyLinkedError>
71 where Msg: $crate::Message<Self> + 'static
72 {
73 self.storage().store_channel::<Msg, Msg::Channel, Self>(None, Some(tx))
74 }
75
76 fn store_channel<Msg>(
77 &self,
78 rx: <Msg::Channel as $crate::Channel>::Rx,
79 tx: <Msg::Channel as $crate::Channel>::Tx
80 ) -> Result<(), $crate::error::AlreadyLinkedError>
81 where Msg: $crate::Message<Self> + 'static
82 {
83 self.storage().store_channel::<Msg, Msg::Channel, Self>(Some(rx), Some(tx))
84 }
85
86 fn store_resource<R: $crate::Resource<Self>>(&self, resource: R) {
87 self.storage.store_resource::<R, Self>(resource)
88 }
89
90 fn storage(&self) -> &$crate::dyn_bus::DynBusStorage<Self> {
91 &self.storage
92 }
93 }
94 }
95);