forked from sfackler/rust-postgres
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery_portal_iter.rs
38 lines (33 loc) · 980 Bytes
/
query_portal_iter.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
37
38
use fallible_iterator::FallibleIterator;
use futures::stream::{self, Stream};
use std::marker::PhantomData;
use tokio_postgres::impls;
use tokio_postgres::{Error, Row};
/// The iterator returned by the `query_portal_iter` method.
pub struct QueryPortalIter<'a> {
it: stream::Wait<impls::QueryPortal>,
_p: PhantomData<&'a mut ()>,
}
// no-op impl to extend the borrow until drop
impl<'a> Drop for QueryPortalIter<'a> {
fn drop(&mut self) {}
}
impl<'a> QueryPortalIter<'a> {
pub(crate) fn new(stream: impls::QueryPortal) -> QueryPortalIter<'a> {
QueryPortalIter {
it: stream.wait(),
_p: PhantomData,
}
}
}
impl<'a> FallibleIterator for QueryPortalIter<'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),
}
}
}