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
//! Backend preset methods for [`RustvelloBuilder`].
use super::RustvelloBuilder;
impl RustvelloBuilder {
/// Use all in-memory backends (suitable for testing and development).
///
/// No connections are established — backends are created during
/// [`build()`](Self::build).
#[cfg(feature = "mem")]
#[cfg_attr(docsrs, doc(cfg(feature = "mem")))]
pub fn memory(mut self) -> Self {
self.backend_preset = Some(super::BackendPreset::Memory);
self
}
/// Use all SQLite backends with the given database path.
///
/// The database file is opened during [`build()`](Self::build), not here.
#[cfg(feature = "sqlite")]
#[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
pub fn sqlite(mut self, path: &str, app_id: &str) -> Self {
self.backend_preset = Some(super::BackendPreset::Sqlite {
path: path.to_string(),
app_id: app_id.to_string(),
});
self
}
/// Use all Redis backends with the given connection URI.
///
/// The connection pool is created during [`build()`](Self::build), not here.
///
/// # Examples
///
/// ```rust,no_run
/// # use rustvello::prelude::*;
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let app = Rustvello::builder()
/// .redis("redis://127.0.0.1/", "my_app")
/// .build().await?;
/// # Ok(())
/// # }
/// ```
#[cfg(feature = "redis")]
#[cfg_attr(docsrs, doc(cfg(feature = "redis")))]
pub fn redis(mut self, uri: &str, app_id: &str) -> Self {
self.backend_preset = Some(super::BackendPreset::Redis {
uri: uri.to_string(),
app_id: app_id.to_string(),
});
self
}
/// Use all MongoDB backends with the given connection URI and database name.
///
/// The connection pool is created during [`build()`](Self::build), not here.
///
/// # Examples
///
/// ```rust,no_run
/// # use rustvello::prelude::*;
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let app = Rustvello::builder()
/// .mongodb("mongodb://localhost:27017", "rustvello_db", "my_app")
/// .build().await?;
/// # Ok(())
/// # }
/// ```
#[cfg(feature = "mongodb")]
#[cfg_attr(docsrs, doc(cfg(feature = "mongodb")))]
pub fn mongodb(mut self, uri: &str, db_name: &str, app_id: &str) -> Self {
self.backend_preset = Some(super::BackendPreset::MongoDB {
uri: uri.to_string(),
db_name: db_name.to_string(),
app_id: app_id.to_string(),
});
self
}
/// Use a RabbitMQ broker with the given AMQP URI and queue prefix.
///
/// Only sets the broker — orchestrator, state backend, client data store,
/// and trigger store must be provided separately (e.g. via `.redis()` or
/// `.sqlite()`). This matches the Python `pynenc_rabbitmq` plugin which
/// only provides a broker implementation.
///
/// The connection is established during [`build()`](Self::build), not here.
///
/// # Examples
///
/// ```rust,no_run
/// # use rustvello::prelude::*;
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let app = Rustvello::builder()
/// .rabbitmq("amqp://localhost:5672", "myapp")
/// .redis("redis://127.0.0.1/", "my_app")
/// .build().await?;
/// # Ok(())
/// # }
/// ```
#[cfg(feature = "rabbitmq")]
#[cfg_attr(docsrs, doc(cfg(feature = "rabbitmq")))]
pub fn rabbitmq(mut self, uri: &str, prefix: &str) -> Self {
self.rabbitmq_config = Some(super::RabbitMqConfig {
uri: uri.to_string(),
prefix: prefix.to_string(),
});
self
}
/// Use all PostgreSQL backends with the given connection string.
///
/// The connection pool is created during [`build()`](Self::build), not here.
///
/// # Examples
///
/// ```rust,no_run
/// # use rustvello::prelude::*;
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let app = Rustvello::builder()
/// .postgres("postgresql://user:pass@localhost/mydb", "my_app")
/// .build().await?;
/// # Ok(())
/// # }
/// ```
#[cfg(feature = "postgres")]
#[cfg_attr(docsrs, doc(cfg(feature = "postgres")))]
pub fn postgres(mut self, connection_string: &str, app_id: &str) -> Self {
self.backend_preset = Some(super::BackendPreset::Postgres {
connection_string: connection_string.to_string(),
app_id: app_id.to_string(),
});
self
}
/// Use all PostgreSQL backends with TLS encryption.
///
/// Requires both the `postgres` and `tls` features.
#[cfg(all(feature = "postgres", feature = "tls"))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "postgres", feature = "tls"))))]
pub fn postgres_tls(mut self, connection_string: &str, app_id: &str) -> Self {
self.backend_preset = Some(super::BackendPreset::PostgresTls {
connection_string: connection_string.to_string(),
app_id: app_id.to_string(),
});
self
}
/// Use all MongoDB 3.6+ backends with the given connection URI and database name.
///
/// The connection pool is created during [`build()`](Self::build), not here.
///
/// # Examples
///
/// ```rust,no_run
/// # use rustvello::prelude::*;
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let app = Rustvello::builder()
/// .mongo3("mongodb://localhost:27017", "rustvello_db", "my_app")
/// .build().await?;
/// # Ok(())
/// # }
/// ```
#[cfg(feature = "mongodb3")]
#[cfg_attr(docsrs, doc(cfg(feature = "mongodb3")))]
pub fn mongo3(mut self, uri: &str, db_name: &str, app_id: &str) -> Self {
self.backend_preset = Some(super::BackendPreset::Mongo3 {
uri: uri.to_string(),
db_name: db_name.to_string(),
app_id: app_id.to_string(),
});
self
}
}