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
//! # synca
//!
//! Write asynchronous code, and synca will create a synchronous version.
//!
//! ## Examples
//!
//! ### pg_as_calc
//!
//! A library that allows you to use Postgres as a calculator
//!
//! - [README.md](https://github.com/sgr-team/rs_synca/blob/main/examples/pg_as_calc/README.md)
//! - [Cargo.toml](https://github.com/sgr-team/rs_synca/blob/main/examples/pg_as_calc/Cargo.toml)
//! - [src/lib.rs](https://github.com/sgr-team/rs_synca/blob/main/examples/pg_as_calc/src/lib.rs)
//!
//! ## Concept
//!
//! The crate contains one attribute macro "synca" which takes the features expression
//! and replaceable types and attributes.
//!
//! This macro can be applied to the declaration of structures, enums, implementations, traits,
//! modules, functions or macros.
//!
//! ```rust
//! #[synca::synca(
//! feature = "tokio",
//! tokio_postgres::Client => postgres::Client,
//! tokio_postgres::Error => postgres::Error,
//! #[tokio::test] => #[test],
//! )]
//! mod my_mod {
//! type Err = tokio_postgres::Error;
//!
//! pub async fn select(client: &mut tokio_postgres::Client) -> Result<i32, Err> {
//! let row = client.query_one("SELECT 1 + 2 result", &[]).await?;
//!
//! Ok(row.get("result"))
//! }
//! }
//! ```
//!
//! The macro generates the next code:
//!
//! ```rust
//! #[cfg(not(feature = "tokio"))]
//! mod my_mod {
//! type Err = postgres::Error;
//!
//! pub fn select(client: &mut postgres::Client) -> Result<i32, Err> {
//! let row = client.query_one("SELECT 1 + 2 result", &[])?;
//!
//! Ok(row.get("result"))
//! }
//! }
//!
//! #[cfg(feature = "tokio")]
//! mod my_mod {
//! type Err = tokio_postgres::Error;
//!
//! pub async fn select(client: &mut tokio_postgres::Client) -> Result<i32, Err> {
//! let row = client.query_one("SELECT 1 + 2 result", &[]).await?;
//!
//! Ok(row.get("result"))
//! }
//! }
//! ```
use TokenStream;
use ;
use quote;
use crateSyncAAttribute;
/// ## About
///
/// ```no_run
/// #[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))"
///
/// ## Example
/// ```rust
/// #[synca::synca(
/// feature = "tokio",
/// tokio_postgres::Client => postgres::Client,
/// tokio_postgres::Error => postgres::Error,
/// #[tokio::test] => #[test],
/// )]
/// mod my_mod {
/// type Err = tokio_postgres::Error;
///
/// pub async fn select(client: &mut tokio_postgres::Client) -> Result<i32, Err> {
/// let row = client.query_one("SELECT 1 + 2 result", &[]).await?;
///
/// Ok(row.get("result"))
/// }
/// }
/// ```