1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
//! # SyncA
//!
//! ## Docs
//!
//! [SyncA Book](https://synca.sgr-team.dev)
//!
//! ## Example
//!
//! ```rust
//! #[synca::synca(
//! feature = "my_async_feature",
//! async_type => sync_type,
//! #[async_attribute] => #[sync_attribute],
//! )]
//! mod my_mod { }
//! ```
//!
//! This macro can be applied to the declaration of structures, enums, implementations, traits,
//! modules, functions, types, macros and etc.
//!
//! The macro will create a synchronous duplicate of the code, enabled from the feature "cfg(not($features_expr))"
//!
//! ```rust
//! /// The macro will create 2 versions of the my_mod
//! /// With the asynchrony feature enabled - asynchronous version,
//! /// without it - synchronous.
//! /// #[synca::synca(feature = "async")]
//! /// mod my_mod { }
//!
//! #[synca::synca(
//! feature = "async",
//! tokio_postgres::Client => postgres::Client
//! )]
//! struct MyStruct {
//! client: tokio_postgres::Client
//! }
//!
//! /// # Functions
//! ///
//! /// The macro turns asynchronous functions into synchronous
//! /// implementations - removing all the .await calls
//! #[synca::synca(feature = "async")]
//! impl MyStruct {
//! pub async fn first_name(&mut self) -> String {
//! let row = self.client.query_one("SQL", &[]).await.unwrap();
//!
//! row.get("name")
//! }
//! }
//!
//! /// # Types
//! ///
//! /// synca supports type substitution
//! /// The synchronous version will use type postgres::Client
//! #[synca::synca(
//! feature = "async",
//! tokio_postgres::Client => postgres::Client
//! )]
//! struct MyStructTypes {
//! client: tokio_postgres::Client
//! }
//!
//! /// # Tests
//! ///
//! /// synca support attributes substitution too.
//! /// This allows you to test not only the asynchronous version, but also the synchronous one
//! #[synca::synca(
//! feature = "async",
//! tokio_postgres::Client => postgres::Client,
//! #[tokio::test] => #[test]
//! )]
//! mod tests {
//! #[tokio::test]
//! pub async fn my_test() {
//! }
//! }
//!
//! /// # Traits
//! ///
//! /// synca also knows how to work with traits
//! #[synca::synca(
//! feature = "async",
//! tokio_postgres::Client => postgres::Client,
//! )]
//! #[async_trait::async_trait]
//! pub trait MyTrait {
//! async fn get_name(client: &mut tokio_postgres::Client);
//! }
//!
//! /// # Docs
//! ///
//! /// synca also contains a documentation processor that allows to generate
//! /// different documentation for the synchronous and asynchronous versions
//! ///
//! /// [synca::sync]
//! /// It's sync doc
//! /// [/synca::sync]
//! /// [synca::async]
//! /// It's async doc
//! /// [/synca::async]
//! ///
//! /// # Match
//! ///
//! /// You can also use "synca::match" to replace part of a string.
//! ///
//! /// Arguments
//! /// - [synca::match]tokio_postgres|postgres[/synca::match]::Client - postgres client
//! #[synca::synca(
//! feature = "async",
//! tokio_postgres::Client => postgres::Client,
//! )]
//! pub async fn my_fn(client: &mut tokio_postgres::Client) { }
//!
//! /// # Virtual attributes
//! ///
//! /// - synca::ignore - ignore in code fold
//! /// - synca::sync_only - the code will only be available in the synchronous version
//! /// - synca::async_only - the code will only be available in the asynchronous version
//! #[synca::synca(
//! feature = "async",
//! tokio_postgres::Client => postgres::Client,
//! #[tokio::test] => #[test],
//! )]
//! mod my_mod {
//! #[tokio::test]
//! async fn my_test() {
//! #[synca::ignore]
//! assert_eq!(format!(".aw{}", "ait"), ".await");
//! }
//!
//! #[test]
//! #[synca::sync_only]
//! fn sync_test() {
//! }
//!
//! #[test]
//! #[synca::async_only]
//! fn async_test() {
//! }
//! }
//! ```
pub use *;
use TokenStream;
use ;
use quote;
use crateSyncAInput;
/// Macro for generating a synchronous version of the code.
///
/// Can be applied to any item of the rust language.
///
/// # Example
///
/// ```no_run
/// #[synca::synca(
/// feature = "my_async_feature",
/// tokio_postgres::Client => postgres::Client,
/// tokio_postgres::Error => postgres::Error,
/// #[tokio::test] => #[test],
/// )]
/// mod my_mod {
/// struct MyStructFn {
/// pub client: tokio_postgres::Client
/// }
///
/// #[cfg(test)]
/// mod tests {
/// #[tokio::test]
/// async fn my_test() {
/// }
/// }
/// }
/// ```
/// Allows you to ignore a marked item.
///
/// Can be applied to any item of the rust language.
///
/// ```rust
/// #[synca::synca(
/// feature = "tokio",
/// #[tokio::test] => #[test],
/// )]
/// mod tests {
/// #[tokio::test]
/// pub async fn my_test() {
/// #[synca::ignore]
/// assert_eq!(format!(".aw{}", "ait"), ".await");
/// }
/// }
/// Allows you to leave a marked item in only one of the code versions.
///
/// Can be applied to any item of the rust language.
///
/// ```rust
/// #[synca::synca(feature = "tokio")]
/// mod my_mod {
/// #[synca::only(async)]
/// pub async fn connect_async() {
/// // async code here
/// }
///
/// #[synca::only(sync)]
/// pub fn connect_sync() {
/// // sync code here
/// }
/// }
/// ```