From 855a0f8e411a4443d190072a4894574a13fe7945 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 20 Oct 2020 13:35:08 +0200 Subject: [PATCH] Reorder re-exports in sqlx-rt/lib.rs so they finally are all in the right sections --- sqlx-rt/src/lib.rs | 72 +++++++++++++++++++++++----------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/sqlx-rt/src/lib.rs b/sqlx-rt/src/lib.rs index d9fa47eb..bd78c249 100644 --- a/sqlx-rt/src/lib.rs +++ b/sqlx-rt/src/lib.rs @@ -41,6 +41,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 = 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(future: F) -> F::Output { + RUNTIME.enter(|| RUNTIME.handle().block_on(future)) + } + + pub fn enter_runtime(f: F) -> R + where + F: FnOnce() -> R, + { + RUNTIME.enter(f) + } +} + #[cfg(all( feature = "_tls-native-tls", any(feature = "_rt-tokio", feature = "_rt-actix"), @@ -116,9 +150,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")), @@ -137,36 +168,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 = 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(future: F) -> F::Output { - RUNTIME.enter(|| RUNTIME.handle().block_on(future)) - } - - pub fn enter_runtime(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};