forked from rust-postgres/rust-postgres
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrow_iter.rs
More file actions
34 lines (29 loc) · 765 Bytes
/
Copy pathrow_iter.rs
File metadata and controls
34 lines (29 loc) · 765 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
use crate::Rt;
use fallible_iterator::FallibleIterator;
use futures::StreamExt;
use std::pin::Pin;
use tokio_postgres::{Error, Row, RowStream};
/// The iterator returned by `query_raw`.
pub struct RowIter<'a> {
runtime: Rt<'a>,
it: Pin<Box<RowStream>>,
}
// no-op impl to extend the borrow until drop
impl Drop for RowIter<'_> {
fn drop(&mut self) {}
}
impl<'a> RowIter<'a> {
pub(crate) fn new(runtime: Rt<'a>, stream: RowStream) -> RowIter<'a> {
RowIter {
runtime,
it: Box::pin(stream),
}
}
}
impl FallibleIterator for RowIter<'_> {
type Item = Row;
type Error = Error;
fn next(&mut self) -> Result<Option<Row>, Error> {
self.runtime.block_on(self.it.next()).transpose()
}
}