From ecec956f67a8f5895fc4a64970e0ec3872c9de85 Mon Sep 17 00:00:00 2001 From: Ryan Leckey Date: Wed, 20 Jan 2021 19:48:41 -0800 Subject: [PATCH] fix(sqlx): minor blocking fixes --- sqlx-mysql/src/connection.rs | 4 ++-- sqlx-mysql/src/options.rs | 4 ++-- sqlx/Cargo.toml | 2 +- sqlx/src/mysql/blocking/connection.rs | 8 ++++---- sqlx/src/mysql/blocking/options.rs | 16 ++++++++-------- sqlx/src/mysql/connection.rs | 2 +- sqlx/src/mysql/options.rs | 2 +- sqlx/src/runtime.rs | 10 ++++------ 8 files changed, 23 insertions(+), 25 deletions(-) diff --git a/sqlx-mysql/src/connection.rs b/sqlx-mysql/src/connection.rs index 6982027e..97cd843f 100644 --- a/sqlx-mysql/src/connection.rs +++ b/sqlx-mysql/src/connection.rs @@ -108,10 +108,10 @@ impl Close for MySqlConnection { #[cfg(feature = "blocking")] mod blocking { - use super::{MySqlConnectOptions, MySqlConnection}; - use sqlx_core::blocking::{Close, Connect, Connection, Runtime}; + use super::{MySqlConnectOptions, MySqlConnection}; + impl Connection for MySqlConnection { #[inline] fn ping(&mut self) -> sqlx_core::Result<()> { diff --git a/sqlx-mysql/src/options.rs b/sqlx-mysql/src/options.rs index 2787f258..79d654d6 100644 --- a/sqlx-mysql/src/options.rs +++ b/sqlx-mysql/src/options.rs @@ -88,10 +88,10 @@ where #[cfg(feature = "blocking")] mod blocking { - use super::{MySqlConnectOptions, MySqlConnection}; - use sqlx_core::blocking::{ConnectOptions, Runtime}; + use super::{MySqlConnectOptions, MySqlConnection}; + impl ConnectOptions for MySqlConnectOptions { fn connect(&self) -> sqlx_core::Result where diff --git a/sqlx/Cargo.toml b/sqlx/Cargo.toml index b32883d0..e4d67ece 100644 --- a/sqlx/Cargo.toml +++ b/sqlx/Cargo.toml @@ -21,7 +21,7 @@ blocking = ["sqlx-core/blocking"] # abstract async runtime # not meant to be used directly # activates several crates used in all async runtimes -async = ["futures-util"] +async = ["futures-util", "sqlx-core/async"] # async runtimes async-std = ["async", "sqlx-core/async-std"] diff --git a/sqlx/src/mysql/blocking/connection.rs b/sqlx/src/mysql/blocking/connection.rs index 619e44fb..0aa430c7 100644 --- a/sqlx/src/mysql/blocking/connection.rs +++ b/sqlx/src/mysql/blocking/connection.rs @@ -1,4 +1,4 @@ -use crate::blocking::{self, Close, Connect, Connection, Runtime}; +use crate::blocking::{Close, Connect, Connection, Runtime}; use crate::mysql::connection::MySqlConnection; use crate::{Blocking, Result}; @@ -40,20 +40,20 @@ impl MySqlConnection { impl Close for MySqlConnection { #[inline] fn close(self) -> Result<()> { - self.close() + self.0.close() } } impl Connect for MySqlConnection { #[inline] fn connect(url: &str) -> Result { - Self::connect(url) + sqlx_mysql::MySqlConnection::::connect(url).map(Self) } } impl Connection for MySqlConnection { #[inline] fn ping(&mut self) -> Result<()> { - self.ping() + self.0.ping() } } diff --git a/sqlx/src/mysql/blocking/options.rs b/sqlx/src/mysql/blocking/options.rs index 993889e5..55d75c7b 100644 --- a/sqlx/src/mysql/blocking/options.rs +++ b/sqlx/src/mysql/blocking/options.rs @@ -9,20 +9,20 @@ impl MySqlConnectOptions { /// this: [`connect`](#method.connect). /// /// Implemented with [`ConnectOptions::connect`]. - pub fn connect(&self) -> Result> { - as ConnectOptions>::connect(&self.0) - .map(MySqlConnectOptions::) + #[inline] + pub fn connect(&self) -> Result> { + as ConnectOptions>::connect(&self.0) + .map(MySqlConnection::) } } -impl ConnectOptions for MySqlConnectOptions -where - Rt: Runtime, -{ +impl ConnectOptions for MySqlConnectOptions { + #[inline] fn connect(&self) -> Result where Self::Connection: Sized, { - self.connect() + as ConnectOptions>::connect(&self.0) + .map(MySqlConnection::) } } diff --git a/sqlx/src/mysql/connection.rs b/sqlx/src/mysql/connection.rs index 69379cfd..bd839b7b 100644 --- a/sqlx/src/mysql/connection.rs +++ b/sqlx/src/mysql/connection.rs @@ -1,7 +1,7 @@ use std::fmt::{self, Debug, Formatter}; #[cfg(feature = "async")] -use futures_util::future::{BoxFuture, FutureExt, TryFutureExt}; +use futures_util::future::{BoxFuture, FutureExt}; use super::{MySql, MySqlConnectOptions}; #[cfg(feature = "async")] diff --git a/sqlx/src/mysql/options.rs b/sqlx/src/mysql/options.rs index c4c1ab2e..184f5acf 100644 --- a/sqlx/src/mysql/options.rs +++ b/sqlx/src/mysql/options.rs @@ -2,7 +2,7 @@ use std::fmt::{self, Debug, Formatter}; use std::str::FromStr; #[cfg(feature = "async")] -use futures_util::future::{BoxFuture, FutureExt, TryFutureExt}; +use futures_util::future::{BoxFuture, FutureExt}; use crate::mysql::MySqlConnection; #[cfg(feature = "async")] diff --git a/sqlx/src/runtime.rs b/sqlx/src/runtime.rs index 9d5bdc06..222ab316 100644 --- a/sqlx/src/runtime.rs +++ b/sqlx/src/runtime.rs @@ -3,14 +3,12 @@ // 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(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(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")),