From 8202ec1770642e0935e41286db7acc1f16e8bb84 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Mon, 15 Oct 2018 17:43:04 -0400 Subject: [PATCH] Blocked on rust-lang/rust#55099 --- src/lib.rs | 1 + src/resultset.rs | 44 +++++++++++++++++++++----------------------- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 3c68c63..4d97aad 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -79,6 +79,7 @@ //! ``` #![deny(missing_docs)] #![feature(nll)] +#![feature(existential_type)] // Note to developers: you can find decent overviews of the protocol at // diff --git a/src/resultset.rs b/src/resultset.rs index 167ef01..f7ff821 100644 --- a/src/resultset.rs +++ b/src/resultset.rs @@ -24,6 +24,9 @@ pub struct StatementMetaWriter { pub(crate) stmts: HashMap, } +existential type ReplyFut: + Future, Error = io::Error>; + impl StatementMetaWriter { /// Reply to the client with the given meta-information. /// @@ -32,18 +35,12 @@ impl StatementMetaWriter { /// parameters the client must provide when executing the prepared statement. `columns` is a /// second set of [`Column`](struct.Column.html) descriptors for the values that will be /// returned in each row then the statement is later executed. - pub fn reply<'a, PI, CI>( - mut self, - id: u32, - params: PI, - columns: CI, - ) -> impl Future, Error = io::Error> + 'static + pub fn reply<'a, PI, CI>(mut self, id: u32, params: PI, columns: CI) -> ReplyFut where PI: IntoIterator, CI: IntoIterator, ::IntoIter: ExactSizeIterator, ::IntoIter: ExactSizeIterator, - W: 'static, { let params = params.into_iter(); self.stmts.insert( @@ -54,9 +51,10 @@ impl StatementMetaWriter { }, ); - writers::write_prepare_ok(id, params, columns, &mut self.writer) - .into_future() - .and_then(move |_| self.writer.flusher(self.stmts)) + match writers::write_prepare_ok(id, params, columns, &mut self.writer) { + Ok(_) => future::Either::A(self.writer.flusher(self.stmts)), + Err(e) => future::Either::B(future::err(e)), + } } /// Reply to the client's `PREPARE` with an error. @@ -453,25 +451,25 @@ impl<'a, W: Write, M> RowWriter<'a, W, M> { } } +existential type FinishFut: Future, Error = io::Error>; +existential type FinishOneFut: Future, Error = io::Error>; + impl<'a, W: AsyncWrite + 'static, M: PartialMissing> RowWriter<'a, W, M> { /// Indicate to the client that no more rows are coming. - pub fn finish( - self, - ) -> impl Future, Error = io::Error> + 'static { + pub fn finish(self) -> FinishFut { self.finish_one().and_then(|w| w.no_more_results()) } /// End this resultset response, and indicate to the client that no more rows are coming. - pub fn finish_one( - mut self, - ) -> impl Future, Error = io::Error> + 'static { - let r = self.finish_inner(); - let pw = self.result.take().unwrap(); - r.into_future().and_then(move |_| { - // we know that dropping self will see self.finished == true, - // and so Drop won't try to use self.result. - pw.flush() - }) + pub fn finish_one(mut self) -> FinishOneFut { + match self.finish_inner() { + Ok(_) => { + // we know that dropping self will see self.finished == true, + // and so Drop won't try to use self.result. + future::Either::A(self.result.take().unwrap().flush()) + } + Err(e) => future::Either::B(future::err(e)), + } } }