Is there a way with Rust to perform the following operation without making models
mutable? Possibly by using Stream
? The core issue with using uuids.iter().map(...)
appears to be (a) passing/moving &mut conn
into the closure and (b) the fact that DatabaseModel::load
is async
.
// assume:
// uuid: Vec<uuid::Uuid>
// conn: &mut PgConnection from `sqlx`
let mut models = Vec::<DatabaseModel>::new();
for uuid in &uuids {
let model = DatabaseModel::load(conn, uuid).await;
models.extend(model);
}
//.. do immutable stuff with `models`
A more basic toy example without (a) and (b) above may look like the following, which is closer to what I wish for:
let models = uuids.iter().map(|uuid| DatabaseModel::load(uuid));