@@ -5,14 +5,16 @@ use std::str::FromStr;
5
5
use syn:: DeriveInput ;
6
6
7
7
/// Use this on a struct to generate a built adapter around it, including useful impls.
8
- ///
8
+ ///
9
9
/// # Examples
10
10
/// ```
11
11
/// # use gateway_addon_rust::prelude::*;
12
12
/// # use async_trait::async_trait;
13
13
/// #[adapter]
14
- /// struct ExampleAdapter { foo: i32 }
15
- ///
14
+ /// struct ExampleAdapter {
15
+ /// foo: i32,
16
+ /// }
17
+ ///
16
18
/// #[async_trait]
17
19
/// impl Adapter for BuiltExampleAdapter {
18
20
/// async fn on_unload(&mut self) -> Result<(), String> {
@@ -26,13 +28,15 @@ use syn::DeriveInput;
26
28
/// # use gateway_addon_rust::{prelude::*, adapter::AdapterHandleWrapper};
27
29
/// # use std::ops::{Deref, DerefMut};
28
30
/// # use async_trait::async_trait;
29
- /// struct ExampleAdapter { foo: i32 }
30
- ///
31
- /// struct BuiltExampleAdapter{
31
+ /// struct ExampleAdapter {
32
+ /// foo: i32,
33
+ /// }
34
+ ///
35
+ /// struct BuiltExampleAdapter {
32
36
/// data: ExampleAdapter,
33
- /// adapter_handle: AdapterHandle
37
+ /// adapter_handle: AdapterHandle,
34
38
/// }
35
- ///
39
+ ///
36
40
/// impl AdapterHandleWrapper for BuiltExampleAdapter {
37
41
/// fn adapter_handle(&self) -> &AdapterHandle {
38
42
/// &self.adapter_handle
@@ -41,27 +45,30 @@ use syn::DeriveInput;
41
45
/// &mut self.adapter_handle
42
46
/// }
43
47
/// }
44
- ///
48
+ ///
45
49
/// impl BuildAdapter for ExampleAdapter {
46
50
/// type BuiltAdapter = BuiltExampleAdapter;
47
51
/// fn build(data: Self, adapter_handle: AdapterHandle) -> Self::BuiltAdapter {
48
- /// BuiltExampleAdapter { data, adapter_handle }
52
+ /// BuiltExampleAdapter {
53
+ /// data,
54
+ /// adapter_handle,
55
+ /// }
49
56
/// }
50
57
/// }
51
- ///
58
+ ///
52
59
/// impl Deref for BuiltExampleAdapter {
53
60
/// type Target = ExampleAdapter;
54
61
/// fn deref(&self) -> &Self::Target {
55
62
/// &self.data
56
63
/// }
57
64
/// }
58
- ///
65
+ ///
59
66
/// impl DerefMut for BuiltExampleAdapter {
60
67
/// fn deref_mut(&mut self) -> &mut Self::Target {
61
68
/// &mut self.data
62
69
/// }
63
70
/// }
64
- ///
71
+ ///
65
72
/// #[async_trait]
66
73
/// impl Adapter for BuiltExampleAdapter {
67
74
/// // ...
@@ -72,6 +79,84 @@ pub fn adapter(_args: TokenStream, input: TokenStream) -> TokenStream {
72
79
apply_macro ( input, "adapter" , "Adapter" )
73
80
}
74
81
82
+ /// Use this on a struct to generate a built device around it, including useful impls.
83
+ ///
84
+ /// # Examples
85
+ /// ```
86
+ /// # use gateway_addon_rust::prelude::*;
87
+ /// # use async_trait::async_trait;
88
+ /// #[device]
89
+ /// struct ExamplDevice {
90
+ /// foo: i32,
91
+ /// }
92
+ ///
93
+ /// impl DeviceStructure for ExampleDevice {
94
+ /// // ...
95
+ /// # fn id(&self) -> String {
96
+ /// # "example-device".to_owned()
97
+ /// # }
98
+ /// # fn description(&self) -> DeviceDescription {
99
+ /// # DeviceDescription::default()
100
+ /// # }
101
+ /// }
102
+ ///
103
+ /// #[async_trait]
104
+ /// impl Device for BuiltExampleDevice {}
105
+ /// ```
106
+ /// will expand to
107
+ /// ```
108
+ /// # use gateway_addon_rust::{prelude::*, device::DeviceHandleWrapper};
109
+ /// # use std::ops::{Deref, DerefMut};
110
+ /// # use async_trait::async_trait;
111
+ /// struct ExampleDevice { foo: i32 }
112
+ ///
113
+ /// struct BuiltExampleDevice{
114
+ /// data: ExampleDevice,,
115
+ /// device_handle: DeviceHandle
116
+ /// }
117
+ ///
118
+ /// impl DeviceHandleWrapper for BuiltExampleDevice {
119
+ /// fn device_handle(&self) -> &DeviceHandle {
120
+ /// &self.device_handle
121
+ /// }
122
+ /// fn device_handle_mut(&mut self) -> &mut DeviceHandle {
123
+ /// &mut self.device_handle
124
+ /// }
125
+ /// }
126
+ ///
127
+ /// impl BuildDevice for ExampleDevice {
128
+ /// type BuiltDevice = BuiltExampleDevice;
129
+ /// fn build(data: Self, device_handle: DeviceHandle) -> Self::BuiltDevice {
130
+ /// BuiltExampleDevice { data, device_handle }
131
+ /// }
132
+ /// }
133
+ ///
134
+ /// impl Deref for BuiltExampleDevice {
135
+ /// type Target = ExampleDevice;
136
+ /// fn deref(&self) -> &Self::Target {
137
+ /// &self.data
138
+ /// }
139
+ /// }
140
+ ///
141
+ /// impl DerefMut for BuiltExampleDevice {
142
+ /// fn deref_mut(&mut self) -> &mut Self::Target {
143
+ /// &mut self.data
144
+ /// }
145
+ /// }
146
+ ///
147
+ /// impl DeviceStructure for ExampleDevice {
148
+ /// // ...
149
+ /// # fn id(&self) -> String {
150
+ /// # "example-device".to_owned()
151
+ /// # }
152
+ /// # fn description(&self) -> DeviceDescription {
153
+ /// # DeviceDescription::default()
154
+ /// # }
155
+ /// }
156
+ ///
157
+ /// #[async_trait]
158
+ /// impl Device for BuiltExampleDevice {}
159
+ /// ```
75
160
#[ proc_macro_attribute]
76
161
pub fn device ( _args : TokenStream , input : TokenStream ) -> TokenStream {
77
162
apply_macro ( input, "device" , "Device" )
0 commit comments