Having some trouble with tokio postgress

Hello All,

So the example I'm providing is a very trimmed down version of what I want to do but hopefully should be enough of an example for you guys to help. I'm trying to build a load of queries(Futures) and let them all be driven by Futuresunordered. The issue is that the library will only take a reference but trying to map into that get's tricky. Here is the example:

use tokio;
use tokio_postgres::{NoTls,types::ToSql,Row,error::Error};
use futures::{stream::{self,futures_unordered::FuturesUnordered,StreamExt},future};

struct People {
    name: String,
    age: i32

async fn main() {
    let client = SecretsManagerClient::new(rusoto_core::Region::default());
    // reporting is just the tokio_postgress client
    let reporting = credentials(&client, env::var("REPORTING_SECRET").unwrap()).await;

    let people = vec![("Mark",23),("Mindy",20),("Sam",21)];

            name: person.0.to_owned(),
            age: person.1
    .map(|item|  {
        reporting.query("INSERT INTO public.tbl_people(
            VALUES (
            $2::TEXT,", &[&item.name,&item.age])


As you can imagine the issue I get is "cannot return value referencing local data item.name" the problem is I can't work out how to get round it because tokio_postgress requires it to be a reference and rust requires it to not be that.

Thanks in advance,


Where exactly do you get the error message?

On the line

$2::TEXT,", &[&item.name,&item.age])

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.