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
//! # remove-async-await
//!
//! A procedural macro to make an async function blocking by removing async and awaits. Useful for crates with practically identical blocking and async implementations, aside from having to use `.await`
//! on some function calls.
//!
//! ## Adding as a dependency
//!
//! It is recommended to point the dependency to 1.0 so you get any bug fixes I have to make:
//!
//! ```toml
//! [dependencies]
//! remove-async-await = "1.0"
//! ```
//!
//! ## Example
//!
//! This example assumes you want to keep your async API behind an optional feature called `async`.
//!
//! ```rs
//! #[cfg_attr(not(feature = "async"), remove_async_await::remove_async_await)]
//! async fn get_string() -> String {
//! "hello world".to_owned()
//! }
//!
//! #[cfg_attr(not(feature = "async"), remove_async_await::remove_async_await)]
//! pub async fn print() {
//! let string = get_string().await;
//! println!("{}", string);
//! }
//! ```
//!
//! In this example, if the `async` feature is not used, it would expand to this:
//!
//! ```rs
//! fn get_string() -> String {
//! "hello world".to_owned()
//! }
//!
//! pub fn print() {
//! let string = get_string();
//! println!("{}", string);
//! }
//! ```
//!
//! However, if the `async` feature is used, the code will be unaffected.
//!
//! You can find more examples in the [`tests/` directory](https://github.com/naturecodevoid/remove-async-await/tree/main/tests).
//!
//! ## `remove_async_await_string`
//!
//! There are 2 macros this library provides:
//!
//! 1. `remove_async_await`: The one you should almost always use. Uses `syn` to parse rust code and remove async from functions and await from expressions. Currently, it can only take a function as an
//! input.
//! 2. `remove_async_await_string`: You should only use this one if `remove_async_await` doesn't work for your use case. This is the "dumb macro"; it
//! [literally just removes all occurrences of `async` and `.await` from the string representation of the input](https://github.com/naturecodevoid/remove-async-await/blob/main/src/lib.rs#L192). This
//! means that while it might work with things other than functions, **you shouldn't use it because if a function or variable name contains "async" or ".await", your code will break.**
//!
//! ## Known issues
//!
//! Here is a list of known issues/limitations that I probably won't fix (PRs are welcome!):
//!
//! - **Issue**: `.await` is not removed when calling a macro
//!
//! **Workarounds**:
//!
//! - Move the expression using `.await` to a local variable.
//!
//! Example:
//!
//! ```rs
//! #[remove_async_await::remove_async_await)]
//! async fn issue() {
//! println!("{}", get_string().await); // `.await` will not be removed
//! }
//!
//! #[remove_async_await::remove_async_await)]
//! async fn workaround() {
//! let string = get_string().await; // `.await` **will** be removed
//! println!("{}", string);
//! }
//! ```
//!
//! - Use [`remove_async_await_string`](#remove_async_await_string) (read docs for more info, such as potential bad side effects)
//!
//! Example:
//!
//! ```rs
//! #[remove_async_await::remove_async_await)]
//! async fn issue() {
//! println!("{}", get_string().await); // `.await` will not be removed
//! }
//!
//! #[remove_async_await::remove_async_await_string)]
//! async fn workaround() {
//! println!("{}", get_string().await); // `.await` **will** be removed
//! }
//! ```
//!
//! If you want me to add an issue to this list (or fix the issue), please [create a GitHub issue](https://github.com/naturecodevoid/remove-async-await/issues/new)!
use TokenStream;
use ;
use ;
;
/// Please see crate level documentation for usage and examples.
/// Please see crate level documentation for usage and examples. (Specifically the `remove_async_await_string` section)