forked from transact-rs/sqlx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruntime.rs
More file actions
61 lines (58 loc) · 2.18 KB
/
Copy pathruntime.rs
File metadata and controls
61 lines (58 loc) · 2.18 KB
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
// pick a default runtime
// this is so existing applications in SQLx pre 0.6 work and to
// make it more convenient, if your application only uses 1 runtime (99%+)
// most of the time you won't have to worry about picking the runtime
mod default {
#[cfg(all(not(all(feature = "async-std", feature = "tokio")), feature = "actix"))]
pub use sqlx_core::Actix as Runtime;
#[cfg(feature = "async-std")]
pub use sqlx_core::AsyncStd as Runtime;
#[cfg(all(not(feature = "async-std"), feature = "tokio"))]
pub use sqlx_core::Tokio as Runtime;
#[cfg(all(
not(any(feature = "async-std", feature = "tokio", feature = "actix")),
feature = "blocking"
))]
pub use crate::Blocking as Runtime;
// when there is no async runtime, and the blocking runtime is not present
// the unit type is implemented for Runtime, this is only to allow the
// lib to compile, the lib is mostly useless in this state
#[cfg(not(any(
feature = "async-std",
feature = "actix",
feature = "tokio",
feature = "blocking"
)))]
pub type Runtime = ();
}
/// The default runtime in use by SQLx when one is unspecified.
///
/// Following the crate features for each runtime are activated, a default is picked
/// by following a priority list. The actual sorting here is mostly arbitrary (what is
/// important is that there _is_ a stable ordering).
///
/// 1. [`AsyncStd`][crate::AsyncStd]
/// 2. [`Tokio`][crate::Tokio]
/// 3. [`Actix`][crate::Actix]
/// 4. [`Blocking`][crate::Blocking]
/// 5. `()` - No runtime selected (nothing is possible)
///
/// The intent is to allow the following to cleanly work, regardless of the enabled runtime,
/// if only one runtime is enabled.
///
/// <br>
///
/// ```rust,ignore
/// use sqlx::postgres::{PgConnection, PgConnectOptions};
///
/// // PgConnection<Rt = sqlx::DefaultRuntime>
/// let conn: PgConnection = PgConnectOptions::new()
/// .host("localhost")
/// .username("postgres")
/// .password("password")
/// // .connect()?; // for Blocking runtime
/// .connect().await?; // for Async runtimes
/// ```
///
#[allow(clippy::module_name_repetitions)]
pub type DefaultRuntime = default::Runtime;