Skip to content

Commit c9f53c0

Browse files
committed
added Send bound on the underlying stream, added test
1 parent b9531bb commit c9f53c0

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "tokio-postgres-rustls"
33
description = "Rustls integration for tokio-postgres"
4-
version = "0.1.0"
4+
version = "0.2.0"
55
authors = ["jbg <jbg@dtmf.io>"]
66
edition = "2018"
77
license = "MIT"
@@ -14,3 +14,6 @@ tokio-io = "0.1.12"
1414
tokio-postgres = "0.4.0-rc.3"
1515
tokio-rustls = "0.10.0-alpha.3"
1616
webpki = "0.19.1"
17+
18+
[dev-dependencies]
19+
tokio = "0.1.21"

src/lib.rs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ impl MakeRustlsConnect {
2323

2424
impl<S> MakeTlsConnect<S> for MakeRustlsConnect
2525
where
26-
S: AsyncRead + AsyncWrite + 'static
26+
S: AsyncRead + AsyncWrite + Send + 'static
2727
{
2828
type Stream = TlsStream<S>;
2929
type TlsConnect = RustlsConnect;
@@ -46,11 +46,11 @@ pub struct RustlsConnect {
4646

4747
impl<S> TlsConnect<S> for RustlsConnect
4848
where
49-
S: AsyncRead + AsyncWrite + 'static
49+
S: AsyncRead + AsyncWrite + Send + 'static
5050
{
5151
type Stream = TlsStream<S>;
5252
type Error = io::Error;
53-
type Future = Box<dyn Future<Item=(Self::Stream, ChannelBinding), Error=Self::Error>>;
53+
type Future = Box<dyn Future<Item=(Self::Stream, ChannelBinding), Error=Self::Error> + Send>;
5454

5555
fn connect(self, stream: S) -> Self::Future {
5656
Box::new(
@@ -59,3 +59,31 @@ where
5959
)
6060
}
6161
}
62+
63+
#[cfg(test)]
64+
mod tests {
65+
use futures::{Future, Stream};
66+
use tokio::runtime::current_thread;
67+
68+
#[test]
69+
fn it_works() {
70+
let config = rustls::ClientConfig::new();
71+
let tls = super::MakeRustlsConnect::new(config);
72+
current_thread::block_on_all(
73+
tokio_postgres::connect("sslmode=require host=localhost user=postgres", tls)
74+
.map(|(client, connection)| {
75+
tokio::spawn(
76+
connection.map_err(|e| panic!("{:?}", e))
77+
);
78+
client
79+
})
80+
.and_then(|mut client| {
81+
client.prepare("SELECT 1")
82+
.map(|s| (client, s))
83+
})
84+
.and_then(|(mut client, statement)| {
85+
client.query(&statement, &[]).collect()
86+
})
87+
).unwrap();
88+
}
89+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy