Skip to content

Commit 7df7fc7

Browse files
committed
Start on runtime API
1 parent 707b87a commit 7df7fc7

12 files changed

Lines changed: 127 additions & 18 deletions

File tree

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,6 @@ jobs:
3737
- run: cargo fmt --all -- --check
3838
- run: cargo clippy --all
3939
- run: cargo test --all
40+
- run: cargo test --manifest-path tokio-postgres/Cargo.toml --no-default-features
4041
- run: cargo test --manifest-path tokio-postgres/Cargo.toml --all-features
4142
- *SAVE_DEPS

tokio-postgres-native-tls/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ futures = "0.1"
99
native-tls = "0.2"
1010
tokio-io = "0.1"
1111
tokio-tls = "0.2"
12-
tokio-postgres = { version = "0.3", path = "../tokio-postgres" }
12+
tokio-postgres = { version = "0.3", path = "../tokio-postgres", default-features = false }
1313

1414
[dev-dependencies]
1515
tokio = "0.1.7"

tokio-postgres-native-tls/src/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ where
1515

1616
let handshake = TcpStream::connect(&"127.0.0.1:5433".parse().unwrap())
1717
.map_err(|e| panic!("{}", e))
18-
.and_then(|s| builder.connect(s, tls));
18+
.and_then(|s| builder.handshake(s, tls));
1919
let (mut client, connection) = runtime.block_on(handshake).unwrap();
2020
let connection = connection.map_err(|e| panic!("{}", e));
2121
runtime.spawn(connection);

tokio-postgres-openssl/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ futures = "0.1"
99
openssl = "0.10"
1010
tokio-io = "0.1"
1111
tokio-openssl = "0.3"
12-
tokio-postgres = { version = "0.3", path = "../tokio-postgres" }
12+
tokio-postgres = { version = "0.3", path = "../tokio-postgres", default-features = false }
1313

1414
[dev-dependencies]
1515
tokio = "0.1.7"

tokio-postgres-openssl/src/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ where
1515

1616
let handshake = TcpStream::connect(&"127.0.0.1:5433".parse().unwrap())
1717
.map_err(|e| panic!("{}", e))
18-
.and_then(|s| builder.connect(s, tls));
18+
.and_then(|s| builder.handshake(s, tls));
1919
let (mut client, connection) = runtime.block_on(handshake).unwrap();
2020
let connection = connection.map_err(|e| panic!("{}", e));
2121
runtime.spawn(connection);

tokio-postgres/Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ features = [
2727
circle-ci = { repository = "sfackler/rust-postgres" }
2828

2929
[features]
30+
default = ["runtime"]
31+
runtime = ["tokio-tcp", "tokio-uds"]
32+
3033
"with-bit-vec-0.5" = ["bit-vec-05"]
3134
"with-chrono-0.4" = ["chrono-04"]
3235
"with-eui48-0.4" = ["eui48-04"]
@@ -48,6 +51,8 @@ tokio-codec = "0.1"
4851
tokio-io = "0.1"
4952
void = "1.0"
5053

54+
tokio-tcp = { version = "0.1", optional = true }
55+
5156
bit-vec-05 = { version = "0.5", package = "bit-vec", optional = true }
5257
chrono-04 = { version = "0.4", package = "chrono", optional = true }
5358
eui48-04 = { version = "0.4", package = "eui48", optional = true }
@@ -56,6 +61,9 @@ serde-1 = { version = "1.0", package = "serde", optional = true }
5661
serde_json-1 = { version = "1.0", package = "serde_json", optional = true }
5762
uuid-07 = { version = "0.7", package = "uuid", optional = true }
5863

64+
[target.'cfg(unix)'.dependencies]
65+
tokio-uds = { version = "0.2", optional = true }
66+
5967
[dev-dependencies]
6068
tokio = "0.1.7"
6169
env_logger = "0.5"

tokio-postgres/src/builder.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use std::iter;
33
use std::str::{self, FromStr};
44
use tokio_io::{AsyncRead, AsyncWrite};
55

6-
use crate::proto::ConnectFuture;
7-
use crate::{Connect, Error, TlsMode};
6+
use crate::proto::HandshakeFuture;
7+
use crate::{Error, Handshake, TlsMode};
88

99
#[derive(Clone)]
1010
pub struct Builder {
@@ -48,12 +48,12 @@ impl Builder {
4848
Iter(self.params.iter())
4949
}
5050

51-
pub fn connect<S, T>(&self, stream: S, tls_mode: T) -> Connect<S, T>
51+
pub fn handshake<S, T>(&self, stream: S, tls_mode: T) -> Handshake<S, T>
5252
where
5353
S: AsyncRead + AsyncWrite,
5454
T: TlsMode<S>,
5555
{
56-
Connect(ConnectFuture::new(stream, tls_mode, self.params.clone()))
56+
Handshake(HandshakeFuture::new(stream, tls_mode, self.params.clone()))
5757
}
5858
}
5959

tokio-postgres/src/lib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ pub use crate::builder::*;
1010
pub use crate::error::*;
1111
use crate::proto::CancelFuture;
1212
pub use crate::row::{Row, RowIndex};
13+
#[cfg(feature = "runtime")]
14+
pub use crate::socket::Socket;
1315
pub use crate::stmt::Column;
1416
pub use crate::tls::*;
1517
use crate::types::{ToSql, Type};
@@ -18,6 +20,8 @@ mod builder;
1820
pub mod error;
1921
mod proto;
2022
mod row;
23+
#[cfg(feature = "runtime")]
24+
mod socket;
2125
mod stmt;
2226
mod tls;
2327
pub mod types;
@@ -156,12 +160,12 @@ where
156160
}
157161

158162
#[must_use = "futures do nothing unless polled"]
159-
pub struct Connect<S, T>(proto::ConnectFuture<S, T>)
163+
pub struct Handshake<S, T>(proto::HandshakeFuture<S, T>)
160164
where
161165
S: AsyncRead + AsyncWrite,
162166
T: TlsMode<S>;
163167

164-
impl<S, T> Future for Connect<S, T>
168+
impl<S, T> Future for Handshake<S, T>
165169
where
166170
S: AsyncRead + AsyncWrite,
167171
T: TlsMode<S>,
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::proto::{Client, Connection, PostgresCodec, TlsFuture};
1616
use crate::{CancelData, ChannelBinding, Error, TlsMode};
1717

1818
#[derive(StateMachineFuture)]
19-
pub enum Connect<S, T>
19+
pub enum Handshake<S, T>
2020
where
2121
S: AsyncRead + AsyncWrite,
2222
T: TlsMode<S>,
@@ -70,7 +70,7 @@ where
7070
Failed(Error),
7171
}
7272

73-
impl<S, T> PollConnect<S, T> for Connect<S, T>
73+
impl<S, T> PollHandshake<S, T> for Handshake<S, T>
7474
where
7575
S: AsyncRead + AsyncWrite,
7676
T: TlsMode<S>,
@@ -319,12 +319,12 @@ where
319319
}
320320
}
321321

322-
impl<S, T> ConnectFuture<S, T>
322+
impl<S, T> HandshakeFuture<S, T>
323323
where
324324
S: AsyncRead + AsyncWrite,
325325
T: TlsMode<S>,
326326
{
327-
pub fn new(stream: S, tls_mode: T, params: HashMap<String, String>) -> ConnectFuture<S, T> {
328-
Connect::start(TlsFuture::new(stream, tls_mode), params)
327+
pub fn new(stream: S, tls_mode: T, params: HashMap<String, String>) -> HandshakeFuture<S, T> {
328+
Handshake::start(TlsFuture::new(stream, tls_mode), params)
329329
}
330330
}

tokio-postgres/src/proto/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ mod bind;
2222
mod cancel;
2323
mod client;
2424
mod codec;
25-
mod connect;
2625
mod connection;
2726
mod copy_in;
2827
mod copy_out;
2928
mod execute;
29+
mod handshake;
3030
mod portal;
3131
mod prepare;
3232
mod query;
@@ -42,11 +42,11 @@ pub use crate::proto::bind::BindFuture;
4242
pub use crate::proto::cancel::CancelFuture;
4343
pub use crate::proto::client::Client;
4444
pub use crate::proto::codec::PostgresCodec;
45-
pub use crate::proto::connect::ConnectFuture;
4645
pub use crate::proto::connection::Connection;
4746
pub use crate::proto::copy_in::CopyInFuture;
4847
pub use crate::proto::copy_out::CopyOutStream;
4948
pub use crate::proto::execute::ExecuteFuture;
49+
pub use crate::proto::handshake::HandshakeFuture;
5050
pub use crate::proto::portal::Portal;
5151
pub use crate::proto::prepare::PrepareFuture;
5252
pub use crate::proto::query::QueryStream;

0 commit comments

Comments
 (0)