Skip to content

Commit

Permalink
remove BoxFuture's in WithSocket
Browse files Browse the repository at this point in the history
  • Loading branch information
joeydewaal committed Dec 9, 2024
1 parent 031d7b2 commit 35f56c4
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 26 deletions.
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions sqlx-core/src/net/socket/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,15 @@ where
pub trait WithSocket {
type Output;

fn with_socket<S: Socket>(self, socket: S) -> Self::Output;
fn with_socket<S: Socket>(self, socket: S) -> impl std::future::Future<Output = Self::Output> + Send;
}

pub struct SocketIntoBox;

impl WithSocket for SocketIntoBox {
type Output = Box<dyn Socket>;

fn with_socket<S: Socket>(self, socket: S) -> Self::Output {
async fn with_socket<S: Socket>(self, socket: S) -> Self::Output {
Box::new(socket)
}
}
Expand Down Expand Up @@ -197,7 +197,7 @@ pub async fn connect_tcp<Ws: WithSocket>(
let stream = TcpStream::connect((host, port)).await?;
stream.set_nodelay(true)?;

return Ok(with_socket.with_socket(stream));
return Ok(with_socket.with_socket(stream).await);
}

#[cfg(feature = "_rt-async-std")]
Expand All @@ -217,7 +217,7 @@ pub async fn connect_tcp<Ws: WithSocket>(
Ok(s)
});
match stream {
Ok(stream) => return Ok(with_socket.with_socket(stream)),
Ok(stream) => return Ok(with_socket.with_socket(stream).await),
Err(e) => last_err = Some(e),
}
}
Expand Down Expand Up @@ -255,7 +255,7 @@ pub async fn connect_uds<P: AsRef<Path>, Ws: WithSocket>(

let stream = UnixStream::connect(path).await?;

return Ok(with_socket.with_socket(stream));
return Ok(with_socket.with_socket(stream).await);
}

#[cfg(feature = "_rt-async-std")]
Expand All @@ -265,7 +265,7 @@ pub async fn connect_uds<P: AsRef<Path>, Ws: WithSocket>(

let stream = Async::<UnixStream>::connect(path).await?;

Ok(with_socket.with_socket(stream))
Ok(with_socket.with_socket(stream).await)
}

#[cfg(not(feature = "_rt-async-std"))]
Expand Down
4 changes: 2 additions & 2 deletions sqlx-core/src/net/tls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ where
Ws: WithSocket,
{
#[cfg(feature = "_tls-native-tls")]
return Ok(with_socket.with_socket(tls_native_tls::handshake(socket, config).await?));
return Ok(with_socket.with_socket(tls_native_tls::handshake(socket, config).await?).await);

#[cfg(all(feature = "_tls-rustls", not(feature = "_tls-native-tls")))]
return Ok(with_socket.with_socket(tls_rustls::handshake(socket, config).await?));
return Ok(with_socket.with_socket(tls_rustls::handshake(socket, config).await?).await);

#[cfg(not(any(feature = "_tls-native-tls", feature = "_tls-rustls")))]
{
Expand Down
9 changes: 4 additions & 5 deletions sqlx-mysql/src/connection/establish.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use bytes::buf::Buf;
use bytes::Bytes;
use futures_core::future::BoxFuture;

use crate::collation::{CharSet, Collation};
use crate::common::StatementCache;
Expand All @@ -22,7 +21,7 @@ impl MySqlConnection {
None => crate::net::connect_tcp(&options.host, options.port, do_handshake).await?,
};

let stream = handshake.await?;
let stream = handshake?;

Ok(Self {
inner: Box::new(MySqlConnectionInner {
Expand Down Expand Up @@ -187,9 +186,9 @@ impl<'a> DoHandshake<'a> {
}

impl<'a> WithSocket for DoHandshake<'a> {
type Output = BoxFuture<'a, Result<MySqlStream, Error>>;
type Output = Result<MySqlStream, Error>;

fn with_socket<S: Socket>(self, socket: S) -> Self::Output {
Box::pin(self.do_handshake(socket))
async fn with_socket<S: Socket>(self, socket: S) -> Self::Output {
self.do_handshake(socket).await
}
}
2 changes: 1 addition & 1 deletion sqlx-mysql/src/connection/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub(super) async fn maybe_upgrade<S: Socket>(
impl WithSocket for MapStream {
type Output = MySqlStream;

fn with_socket<S: Socket>(self, socket: S) -> Self::Output {
async fn with_socket<S: Socket>(self, socket: S) -> Self::Output {
MySqlStream {
socket: BufferedSocket::new(Box::new(socket)),
server_version: self.server_version,
Expand Down
2 changes: 1 addition & 1 deletion sqlx-postgres/src/connection/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl PgStream {
None => net::connect_tcp(&options.host, options.port, MaybeUpgradeTls(options)).await?,
};

let socket = socket_future.await?;
let socket = socket_future?;

Ok(Self {
inner: BufferedSocket::new(socket),
Expand Down
8 changes: 3 additions & 5 deletions sqlx-postgres/src/connection/tls.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use futures_core::future::BoxFuture;

use crate::error::Error;
use crate::net::tls::{self, TlsConfig};
use crate::net::{Socket, SocketIntoBox, WithSocket};
Expand All @@ -10,10 +8,10 @@ use crate::{PgConnectOptions, PgSslMode};
pub struct MaybeUpgradeTls<'a>(pub &'a PgConnectOptions);

impl<'a> WithSocket for MaybeUpgradeTls<'a> {
type Output = BoxFuture<'a, crate::Result<Box<dyn Socket>>>;
type Output = crate::Result<Box<dyn Socket>>;

fn with_socket<S: Socket>(self, socket: S) -> Self::Output {
Box::pin(maybe_upgrade(socket, self.0))
async fn with_socket<S: Socket>(self, socket: S) -> Self::Output {
maybe_upgrade(socket, self.0).await
}
}

Expand Down

0 comments on commit 35f56c4

Please sign in to comment.