forked from sfackler/rust-postgres
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery.rs
36 lines (31 loc) · 838 Bytes
/
query.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use fallible_iterator::FallibleIterator;
use futures::stream::{self, Stream};
use std::marker::PhantomData;
use tokio_postgres::{Error, Row};
pub struct Query<'a> {
it: stream::Wait<tokio_postgres::Query>,
_p: PhantomData<&'a mut ()>,
}
// no-op impl to extend the borrow until drop
impl<'a> Drop for Query<'a> {
fn drop(&mut self) {}
}
impl<'a> Query<'a> {
pub(crate) fn new(stream: tokio_postgres::Query) -> Query<'a> {
Query {
it: stream.wait(),
_p: PhantomData,
}
}
}
impl<'a> FallibleIterator for Query<'a> {
type Item = Row;
type Error = Error;
fn next(&mut self) -> Result<Option<Row>, Error> {
match self.it.next() {
Some(Ok(row)) => Ok(Some(row)),
Some(Err(e)) => Err(e),
None => Ok(None),
}
}
}