Add Rows::{mapped,and_then} to get an Iterator out of a Rows i… (#676)

This commit is contained in:
Thom Chiovoloni 2020-04-06 13:01:39 -07:00 committed by GitHub
parent 0394e114d0
commit 9b040da029
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -41,6 +41,25 @@ impl<'stmt> Rows<'stmt> {
{
Map { rows: self, f }
}
/// Map over this `Rows`, converting it to a [`MappedRows`], which
/// implements `Iterator`.
pub fn mapped<F, B>(self, f: F) -> MappedRows<'stmt, F>
where
F: FnMut(&Row<'_>) -> Result<B>,
{
MappedRows { rows: self, map: f }
}
/// Map over this `Rows` with a fallible function, converting it to a
/// [`AndThenRows`], which implements `Iterator` (instead of
/// `FallibleStreamingIterator`).
pub fn and_then<F, T, E>(self, f: F) -> AndThenRows<'stmt, F>
where
F: FnMut(&Row<'_>) -> result::Result<T, E>,
{
AndThenRows { rows: self, map: f }
}
}
impl<'stmt> Rows<'stmt> {