Skip to content

Commit 7382e39

Browse files
committed
relax trait bound for postgres try_from_client_and_connection
tokio_postgres::Socket is not supported for wasm32-unknown-unknown target. tokio_postgres, additionally, may return a Connection type whose first bound is not a tokio_postgres::Socket. Accordingly, let's relax the bounds on try_from_client_and_connection so that we match the loosest type that may be returned by tokio_postgres's connection methods, which enables try_from_client_and_connection to work for a wasm32-unknown-unknown target.
1 parent ff3b166 commit 7382e39

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/pg/mod.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use futures_util::TryFutureExt;
2929
use futures_util::{Future, FutureExt, StreamExt};
3030
use std::collections::{HashMap, HashSet};
3131
use std::sync::Arc;
32+
use tokio::io::{AsyncRead, AsyncWrite};
3233
use tokio::sync::broadcast;
3334
use tokio::sync::oneshot;
3435
use tokio::sync::Mutex;
@@ -397,13 +398,13 @@ impl AsyncPgConnection {
397398

398399
/// Constructs a new `AsyncPgConnection` from an existing [`tokio_postgres::Client`] and
399400
/// [`tokio_postgres::Connection`]
400-
#[cfg(not(target_arch = "wasm32"))]
401-
pub async fn try_from_client_and_connection<S>(
401+
pub async fn try_from_client_and_connection<S, T>(
402402
client: tokio_postgres::Client,
403-
conn: tokio_postgres::Connection<tokio_postgres::Socket, S>,
403+
conn: tokio_postgres::Connection<S, T>,
404404
) -> ConnectionResult<Self>
405405
where
406-
S: tokio_postgres::tls::TlsStream + Unpin + Send + 'static,
406+
S: AsyncRead + AsyncWrite + Unpin + Send + 'static,
407+
T: tokio_postgres::tls::TlsStream + Unpin + Send + 'static,
407408
{
408409
let (error_rx, shutdown_tx) = drive_connection(conn);
409410

@@ -879,15 +880,15 @@ async fn drive_future<R>(
879880
}
880881
}
881882

882-
#[cfg(not(target_arch = "wasm32"))]
883-
fn drive_connection<S>(
884-
conn: tokio_postgres::Connection<tokio_postgres::Socket, S>,
883+
fn drive_connection<S, T>(
884+
conn: tokio_postgres::Connection<S, T>,
885885
) -> (
886886
broadcast::Receiver<Arc<tokio_postgres::Error>>,
887887
oneshot::Sender<()>,
888888
)
889889
where
890-
S: tokio_postgres::tls::TlsStream + Unpin + Send + 'static,
890+
S: AsyncRead + AsyncWrite + Unpin + Send + 'static,
891+
T: tokio_postgres::tls::TlsStream + Unpin + Send + 'static,
891892
{
892893
let (error_tx, error_rx) = tokio::sync::broadcast::channel(1);
893894
let (shutdown_tx, shutdown_rx) = tokio::sync::oneshot::channel();

0 commit comments

Comments
 (0)