-
Notifications
You must be signed in to change notification settings - Fork 134
Description
In light of stable async/await, a lot of these collect/try_collect/map/etc. methods seem redundant if we could instead stream the async results.
e.g. this pattern is replicated with minor changes in several places:
pub async fn for_each<F>(self, mut fun: F) -> Result<Self>
where
F: FnMut(Row),
{
if self.is_empty() {
Ok(self)
} else {
let mut qr = self;
loop {
let (qr_, row) = qr.get_row().await?;
qr = qr_;
if let Some(row) = row {
fun(row);
} else {
break Ok(qr);
}
}
}
}Why not simply swap out the fun(row); and instead make that the poll on a Stream?
The big thing this would open up for me, is I could impl From<my::Row> (which would call the FromRow), and then let the From and standard collect() calls build my result sets.
As it's written, I'm stuck forced to build full Vecs of my entire QueryResult, when a stream would let me map, filter, zip, etc., and let type inference handle my result from collecting (could even make a HashMap or whatever). Would also make it a lot easier to return an Err on the very first TryFrom<my::Row> that fails, instead of building the full result with all errors like try_collect does now.