Files
rust-postgres/postgres/src/row_iter.rs
Steven Fackler fd3a99c225 Don't spawn off connection in blocking impl
We can now directly return fatal errors, and intercept notifications
2020-03-22 12:05:00 -07:00

32 lines
774 B
Rust

use crate::connection::ConnectionRef;
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> {
connection: ConnectionRef<'a>,
it: Pin<Box<RowStream>>,
}
impl<'a> RowIter<'a> {
pub(crate) fn new(connection: ConnectionRef<'a>, stream: RowStream) -> RowIter<'a> {
RowIter {
connection,
it: Box::pin(stream),
}
}
}
impl FallibleIterator for RowIter<'_> {
type Item = Row;
type Error = Error;
fn next(&mut self) -> Result<Option<Row>, Error> {
let it = &mut self.it;
self.connection
.block_on(async { it.next().await.transpose() })
}
}