opengauss/
row_iter.rs

1use crate::connection::ConnectionRef;
2use fallible_iterator::FallibleIterator;
3use futures::StreamExt;
4use std::pin::Pin;
5use tokio_opengauss::{Error, Row, RowStream};
6
7/// The iterator returned by `query_raw`.
8pub 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
22impl FallibleIterator for RowIter<'_> {
23    type Item = Row;
24    type Error = Error;
25
26    fn next(&mut self) -> Result<Option<Row>, Error> {
27        let it = &mut self.it;
28        self.connection
29            .block_on(async { it.next().await.transpose() })
30    }
31}