Skip to content

Commit 8202ec1

Browse files
committed
1 parent d5327c1 commit 8202ec1

File tree

2 files changed

+22
-23
lines changed

2 files changed

+22
-23
lines changed

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
//! ```
8080
#![deny(missing_docs)]
8181
#![feature(nll)]
82+
#![feature(existential_type)]
8283

8384
// Note to developers: you can find decent overviews of the protocol at
8485
//

src/resultset.rs

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ pub struct StatementMetaWriter<W> {
2424
pub(crate) stmts: HashMap<u32, StatementData>,
2525
}
2626

27+
existential type ReplyFut<W>:
28+
Future<Item = PartialServiceState<W, MissingService>, Error = io::Error>;
29+
2730
impl<W: AsyncWrite> StatementMetaWriter<W> {
2831
/// Reply to the client with the given meta-information.
2932
///
@@ -32,18 +35,12 @@ impl<W: AsyncWrite> StatementMetaWriter<W> {
3235
/// parameters the client must provide when executing the prepared statement. `columns` is a
3336
/// second set of [`Column`](struct.Column.html) descriptors for the values that will be
3437
/// returned in each row then the statement is later executed.
35-
pub fn reply<'a, PI, CI>(
36-
mut self,
37-
id: u32,
38-
params: PI,
39-
columns: CI,
40-
) -> impl Future<Item = PartialServiceState<W, MissingService>, Error = io::Error> + 'static
38+
pub fn reply<'a, PI, CI>(mut self, id: u32, params: PI, columns: CI) -> ReplyFut<W>
4139
where
4240
PI: IntoIterator<Item = &'a Column>,
4341
CI: IntoIterator<Item = &'a Column>,
4442
<PI as IntoIterator>::IntoIter: ExactSizeIterator,
4543
<CI as IntoIterator>::IntoIter: ExactSizeIterator,
46-
W: 'static,
4744
{
4845
let params = params.into_iter();
4946
self.stmts.insert(
@@ -54,9 +51,10 @@ impl<W: AsyncWrite> StatementMetaWriter<W> {
5451
},
5552
);
5653

57-
writers::write_prepare_ok(id, params, columns, &mut self.writer)
58-
.into_future()
59-
.and_then(move |_| self.writer.flusher(self.stmts))
54+
match writers::write_prepare_ok(id, params, columns, &mut self.writer) {
55+
Ok(_) => future::Either::A(self.writer.flusher(self.stmts)),
56+
Err(e) => future::Either::B(future::err(e)),
57+
}
6058
}
6159

6260
/// Reply to the client's `PREPARE` with an error.
@@ -453,25 +451,25 @@ impl<'a, W: Write, M> RowWriter<'a, W, M> {
453451
}
454452
}
455453

454+
existential type FinishFut<W, M>: Future<Item = PartialServiceState<W, M>, Error = io::Error>;
455+
existential type FinishOneFut<W, M>: Future<Item = QueryResultWriter<W, M>, Error = io::Error>;
456+
456457
impl<'a, W: AsyncWrite + 'static, M: PartialMissing> RowWriter<'a, W, M> {
457458
/// Indicate to the client that no more rows are coming.
458-
pub fn finish(
459-
self,
460-
) -> impl Future<Item = PartialServiceState<W, M>, Error = io::Error> + 'static {
459+
pub fn finish(self) -> FinishFut<W, M> {
461460
self.finish_one().and_then(|w| w.no_more_results())
462461
}
463462

464463
/// End this resultset response, and indicate to the client that no more rows are coming.
465-
pub fn finish_one(
466-
mut self,
467-
) -> impl Future<Item = QueryResultWriter<W, M>, Error = io::Error> + 'static {
468-
let r = self.finish_inner();
469-
let pw = self.result.take().unwrap();
470-
r.into_future().and_then(move |_| {
471-
// we know that dropping self will see self.finished == true,
472-
// and so Drop won't try to use self.result.
473-
pw.flush()
474-
})
464+
pub fn finish_one(mut self) -> FinishOneFut<W, M> {
465+
match self.finish_inner() {
466+
Ok(_) => {
467+
// we know that dropping self will see self.finished == true,
468+
// and so Drop won't try to use self.result.
469+
future::Either::A(self.result.take().unwrap().flush())
470+
}
471+
Err(e) => future::Either::B(future::err(e)),
472+
}
475473
}
476474
}
477475

0 commit comments

Comments
 (0)