Skip to content

Commit 8c3770b

Browse files
committed
Start on tokio-postgres rewrite
1 parent 5ad7850 commit 8c3770b

File tree

18 files changed

+851
-2439
lines changed

18 files changed

+851
-2439
lines changed

Cargo.toml

+6
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,9 @@ 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" }

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

tokio-postgres/Cargo.toml

+7-9
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,19 @@ 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"
4140
postgres-protocol = { version = "0.3.0", path = "../postgres-protocol" }
4241
postgres-shared = { version = "0.4.0", path = "../postgres-shared" }
43-
tokio-core = "0.1.8"
44-
tokio-dns-unofficial = "0.1"
42+
state_machine_future = "0.1.7"
43+
tokio-codec = "0.1"
4544
tokio-io = "0.1"
46-
47-
tokio-openssl = { version = "0.2", optional = true }
48-
openssl = { version = "0.10", optional = true }
45+
tokio-tcp = "0.1"
46+
tokio-timer = "0.2"
4947

5048
[target.'cfg(unix)'.dependencies]
51-
tokio-uds = "0.1"
49+
tokio-uds = "0.2"

0 commit comments

Comments
 (0)