postgres/
row_iter.rs
1use crate::connection::ConnectionRef;
2use fallible_iterator::FallibleIterator;
3use futures_util::StreamExt;
4use std::pin::Pin;
5use tokio_postgres::{Error, Row, RowStream};
6
7pub struct RowIter<'a> {
9 connection: ConnectionRef<'a>,
10 it: Pin<Box<RowStream>>,
11}
12
13impl<'a> RowIter<'a> {
14 pub(crate) fn new(connection: ConnectionRef<'a>, stream: RowStream) -> RowIter<'a> {
15 RowIter {
16 connection,
17 it: Box::pin(stream),
18 }
19 }
20
21 pub fn rows_affected(&self) -> Option<u64> {
25 self.it.rows_affected()
26 }
27}
28
29impl FallibleIterator for RowIter<'_> {
30 type Item = Row;
31 type Error = Error;
32
33 fn next(&mut self) -> Result<Option<Row>, Error> {
34 let it = &mut self.it;
35 self.connection
36 .block_on(async { it.next().await.transpose() })
37 }
38}