forked from rust-postgres/rust-postgres
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple_query_iter.rs
More file actions
37 lines (32 loc) · 960 Bytes
/
Copy pathsimple_query_iter.rs
File metadata and controls
37 lines (32 loc) · 960 Bytes
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
use fallible_iterator::FallibleIterator;
use futures::stream::{self, Stream};
use std::marker::PhantomData;
use tokio_postgres::impls;
use tokio_postgres::{Error, SimpleQueryMessage};
pub struct SimpleQueryIter<'a> {
it: stream::Wait<impls::SimpleQuery>,
_p: PhantomData<&'a mut ()>,
}
// no-op impl to extend borrow until drop
impl<'a> Drop for SimpleQueryIter<'a> {
fn drop(&mut self) {}
}
impl<'a> SimpleQueryIter<'a> {
pub(crate) fn new(stream: impls::SimpleQuery) -> SimpleQueryIter<'a> {
SimpleQueryIter {
it: stream.wait(),
_p: PhantomData,
}
}
}
impl<'a> FallibleIterator for SimpleQueryIter<'a> {
type Item = SimpleQueryMessage;
type Error = Error;
fn next(&mut self) -> Result<Option<SimpleQueryMessage>, Error> {
match self.it.next() {
Some(Ok(row)) => Ok(Some(row)),
Some(Err(e)) => Err(e),
None => Ok(None),
}
}
}