Skip to content

Commit

Permalink
Reorder re-exports in sqlx-rt/lib.rs
Browse files Browse the repository at this point in the history
so they finally are all in the right sections
  • Loading branch information
jplatte committed Oct 20, 2020
1 parent 6adfe58 commit 62b7887
Showing 1 changed file with 36 additions and 36 deletions.
72 changes: 36 additions & 36 deletions sqlx-rt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,40 @@ pub use tokio::{
))]
pub use tokio::net::UnixStream;

#[cfg(all(
any(feature = "_rt-tokio", feature = "_rt-actix"),
not(feature = "_rt-async-std"),
))]
pub use tokio_runtime::{block_on, enter_runtime};

#[cfg(any(feature = "_rt-tokio", feature = "_rt-actix"))]
mod tokio_runtime {
use once_cell::sync::Lazy;
use tokio::runtime::{self, Runtime};

// lazily initialize a global runtime once for multiple invocations of the macros
static RUNTIME: Lazy<Runtime> = Lazy::new(|| {
runtime::Builder::new()
// `.basic_scheduler()` requires calling `Runtime::block_on()` which needs mutability
.threaded_scheduler()
.enable_io()
.enable_time()
.build()
.expect("failed to initialize Tokio runtime")
});

pub fn block_on<F: std::future::Future>(future: F) -> F::Output {
RUNTIME.enter(|| RUNTIME.handle().block_on(future))
}

pub fn enter_runtime<F, R>(f: F) -> R
where
F: FnOnce() -> R,
{
RUNTIME.enter(f)
}
}

#[cfg(all(
feature = "_tls-native-tls",
any(feature = "_rt-tokio", feature = "_rt-actix"),
Expand Down Expand Up @@ -113,9 +147,6 @@ macro_rules! blocking {
))]
pub use async_std::os::unix::net::UnixStream;

#[cfg(all(feature = "async-native-tls", not(feature = "tokio-native-tls")))]
pub use async_native_tls::{TlsConnector, TlsStream};

#[cfg(all(
feature = "_rt-async-std",
not(any(feature = "_rt-actix", feature = "_rt-tokio")),
Expand All @@ -134,36 +165,5 @@ where
f()
}

#[cfg(all(
any(feature = "_rt-tokio", feature = "_rt-actix"),
not(feature = "_rt-async-std"),
))]
pub use tokio_runtime::{block_on, enter_runtime};

#[cfg(any(feature = "_rt-tokio", feature = "_rt-actix"))]
mod tokio_runtime {
use once_cell::sync::Lazy;
use tokio::runtime::{self, Runtime};

// lazily initialize a global runtime once for multiple invocations of the macros
static RUNTIME: Lazy<Runtime> = Lazy::new(|| {
runtime::Builder::new()
// `.basic_scheduler()` requires calling `Runtime::block_on()` which needs mutability
.threaded_scheduler()
.enable_io()
.enable_time()
.build()
.expect("failed to initialize Tokio runtime")
});

pub fn block_on<F: std::future::Future>(future: F) -> F::Output {
RUNTIME.enter(|| RUNTIME.handle().block_on(future))
}

pub fn enter_runtime<F, R>(f: F) -> R
where
F: FnOnce() -> R,
{
RUNTIME.enter(f)
}
}
#[cfg(all(feature = "async-native-tls", not(feature = "tokio-native-tls")))]
pub use async_native_tls::{TlsConnector, TlsStream};

0 comments on commit 62b7887

Please sign in to comment.