Skip to content

Commit 7b5fa05

Browse files
authored
Merge pull request sfackler#363 from sfackler/tokio-rewrite
Tokio rewrite
2 parents 5ad7850 + 70758bc commit 7b5fa05

28 files changed

+1996
-2405
lines changed

.circleci/config.yml

+1-4
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,15 @@ save_deps: &SAVE_DEPS
2121
version: 2
2222
jobs:
2323
build:
24-
working_directory: ~/build
2524
docker:
26-
- image: rust:1.23.0
25+
- image: rust:1.26.2
2726
environment:
2827
RUSTFLAGS: -D warnings
2928
- image: sfackler/rust-postgres-test:4
3029
steps:
3130
- checkout
3231
- *RESTORE_REGISTRY
3332
- run: cargo generate-lockfile
34-
- run: cargo update -p nalgebra --precise 0.14.3 # 0.14.4 requires 1.26 :(
35-
- run: cargo update -p geo-types --precise 0.1.0
3633
- *SAVE_REGISTRY
3734
- run: rustc --version > ~/rust-version
3835
- *RESTORE_DEPS

Cargo.toml

+8
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,11 @@ members = [
88
"postgres-native-tls",
99
"tokio-postgres",
1010
]
11+
12+
[patch.crates-io]
13+
tokio-uds = { git = "https://github.com/sfackler/tokio" }
14+
tokio-io = { git = "https://github.com/sfackler/tokio" }
15+
tokio-timer = { git = "https://github.com/sfackler/tokio" }
16+
tokio-codec = { git = "https://github.com/sfackler/tokio" }
17+
tokio-reactor = { git = "https://github.com/sfackler/tokio" }
18+
tokio-executor = { git = "https://github.com/sfackler/tokio" }

postgres-shared/src/error/mod.rs

+29-28
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
//! Errors.
22
33
use fallible_iterator::FallibleIterator;
4-
use postgres_protocol::message::backend::ErrorFields;
5-
use std::error;
4+
use postgres_protocol::message::backend::{ErrorFields, ErrorResponseBody};
65
use std::convert::From;
6+
use std::error;
77
use std::fmt;
88
use std::io;
99

@@ -214,36 +214,29 @@ impl DbError {
214214
}
215215

216216
Ok(DbError {
217-
severity: severity.ok_or_else(|| {
218-
io::Error::new(io::ErrorKind::InvalidInput, "`S` field missing")
219-
})?,
217+
severity: severity
218+
.ok_or_else(|| io::Error::new(io::ErrorKind::InvalidInput, "`S` field missing"))?,
220219
parsed_severity: parsed_severity,
221-
code: code.ok_or_else(|| {
222-
io::Error::new(io::ErrorKind::InvalidInput, "`C` field missing")
223-
})?,
224-
message: message.ok_or_else(|| {
225-
io::Error::new(io::ErrorKind::InvalidInput, "`M` field missing")
226-
})?,
220+
code: code
221+
.ok_or_else(|| io::Error::new(io::ErrorKind::InvalidInput, "`C` field missing"))?,
222+
message: message
223+
.ok_or_else(|| io::Error::new(io::ErrorKind::InvalidInput, "`M` field missing"))?,
227224
detail: detail,
228225
hint: hint,
229226
position: match normal_position {
230227
Some(position) => Some(ErrorPosition::Normal(position)),
231-
None => {
232-
match internal_position {
233-
Some(position) => {
234-
Some(ErrorPosition::Internal {
235-
position: position,
236-
query: internal_query.ok_or_else(|| {
237-
io::Error::new(
238-
io::ErrorKind::InvalidInput,
239-
"`q` field missing but `p` field present",
240-
)
241-
})?,
242-
})
243-
}
244-
None => None,
245-
}
246-
}
228+
None => match internal_position {
229+
Some(position) => Some(ErrorPosition::Internal {
230+
position: position,
231+
query: internal_query.ok_or_else(|| {
232+
io::Error::new(
233+
io::ErrorKind::InvalidInput,
234+
"`q` field missing but `p` field present",
235+
)
236+
})?,
237+
}),
238+
None => None,
239+
},
247240
},
248241
where_: where_,
249242
schema: schema,
@@ -324,6 +317,14 @@ pub fn db(e: DbError) -> Error {
324317
Error(Box::new(ErrorKind::Db(e)))
325318
}
326319

320+
#[doc(hidden)]
321+
pub fn __db(e: ErrorResponseBody) -> Error {
322+
match DbError::new(&mut e.fields()) {
323+
Ok(e) => Error(Box::new(ErrorKind::Db(e))),
324+
Err(e) => Error(Box::new(ErrorKind::Io(e))),
325+
}
326+
}
327+
327328
#[doc(hidden)]
328329
pub fn io(e: io::Error) -> Error {
329330
Error(Box::new(ErrorKind::Io(e)))
@@ -401,7 +402,7 @@ impl Error {
401402
pub fn as_db(&self) -> Option<&DbError> {
402403
match *self.0 {
403404
ErrorKind::Db(ref err) => Some(err),
404-
_ => None
405+
_ => None,
405406
}
406407
}
407408

postgres-shared/src/params/mod.rs

+10
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
use std::error::Error;
33
use std::mem;
44
use std::path::PathBuf;
5+
use std::str::FromStr;
56
use std::time::Duration;
67

8+
use error;
79
use params::url::Url;
810

911
mod url;
@@ -96,6 +98,14 @@ impl ConnectParams {
9698
}
9799
}
98100

101+
impl FromStr for ConnectParams {
102+
type Err = error::Error;
103+
104+
fn from_str(s: &str) -> Result<ConnectParams, error::Error> {
105+
s.into_connect_params().map_err(error::connect)
106+
}
107+
}
108+
99109
/// A builder for `ConnectParams`.
100110
pub struct Builder {
101111
port: u16,

tokio-postgres/Cargo.toml

+12-9
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,24 @@ circle-ci = { repository = "sfackler/rust-postgres" }
3131
"with-serde_json-1" = ["postgres-shared/with-serde_json-1"]
3232
"with-uuid-0.6" = ["postgres-shared/with-uuid-0.6"]
3333

34-
with-openssl = ["tokio-openssl", "openssl"]
35-
3634
[dependencies]
3735
bytes = "0.4"
3836
fallible-iterator = "0.1.3"
3937
futures = "0.1.7"
40-
futures-state-stream = "0.2"
38+
futures-cpupool = "0.1"
39+
lazy_static = "1.0"
40+
log = "0.4"
4141
postgres-protocol = { version = "0.3.0", path = "../postgres-protocol" }
4242
postgres-shared = { version = "0.4.0", path = "../postgres-shared" }
43-
tokio-core = "0.1.8"
44-
tokio-dns-unofficial = "0.1"
43+
state_machine_future = "0.1.7"
44+
tokio-codec = "0.1"
4545
tokio-io = "0.1"
46-
47-
tokio-openssl = { version = "0.2", optional = true }
48-
openssl = { version = "0.10", optional = true }
46+
tokio-tcp = "0.1"
47+
tokio-timer = "0.2"
4948

5049
[target.'cfg(unix)'.dependencies]
51-
tokio-uds = "0.1"
50+
tokio-uds = "0.2"
51+
52+
[dev-dependencies]
53+
tokio = "0.1.7"
54+
env_logger = "0.5"

0 commit comments

Comments
 (0)