Hi there!
I've got a situation where I have, from user input, a list of identifiers. These identifiers need to be resolved to records from a database, within a single transaction (i.e., they cannot be resolved in parallel; the underlying DBMS doesn't support that within a single tx). I've written this out longhand:
let mut launchers = vec![];
for id in self.launcher {
let launcher = tx.get_launcher(&project, id).await?;
launchers.push(launcher);
}
I would love to understand how to write this as a transform on self.launcher.into_iter()
, instead. If the lookup operation were synchronous, this would be
let launchers: Vec<_> = self.launcher
.map(|id| tx.get_launcher(&project, id))
.collect()?;
However, I haven't been able to ferret out the right combination of tools to do this when the transform yields a future, instead of an immediately-available result. Is this possible?
I have tried a few variations on
use futures::stream::{self, *};
let launchers = stream::iter(self.launcher)
.map(|id| tx.get_launcher(&project, id))
.try_collect();
but I'm not competent to understand the resulting error messages.
error[E0599]: the method `try_collect` exists for struct `futures::stream::Iter<std::iter::Map<std::vec::IntoIter<id::Id>, [closure@src/release/create.rs:34:22: 34:26]>>`, but its trait bounds were not satisfied
--> src/release/create.rs:36:10
|
36 | .try_collect()
| ^^^^^^^^^^^ method cannot be called on `futures::stream::Iter<std::iter::Map<std::vec::IntoIter<id::Id>, [closure@src/release/create.rs:34:22: 34:26]>>` due to unsatisfied trait bounds
|
::: /Users/owen/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-util-0.3.27/src/stream/iter.rs:9:1
|
9 | pub struct Iter<I> {
| ------------------
| |
| doesn't satisfy `_: TryStreamExt`
| doesn't satisfy `_: TryStream`
|
= note: the following trait bounds were not satisfied:
`futures::stream::Iter<std::iter::Map<std::vec::IntoIter<id::Id>, [closure@src/release/create.rs:34:22: 34:26]>>: TryStream`
which is required by `futures::stream::Iter<std::iter::Map<std::vec::IntoIter<id::Id>, [closure@src/release/create.rs:34:22: 34:26]>>: TryStreamExt`
`&futures::stream::Iter<std::iter::Map<std::vec::IntoIter<id::Id>, [closure@src/release/create.rs:34:22: 34:26]>>: TryStream`
which is required by `&futures::stream::Iter<std::iter::Map<std::vec::IntoIter<id::Id>, [closure@src/release/create.rs:34:22: 34:26]>>: TryStreamExt`
`&mut futures::stream::Iter<std::iter::Map<std::vec::IntoIter<id::Id>, [closure@src/release/create.rs:34:22: 34:26]>>: TryStream`
which is required by `&mut futures::stream::Iter<std::iter::Map<std::vec::IntoIter<id::Id>, [closure@src/release/create.rs:34:22: 34:26]>>: TryStreamExt`