Future returned by run_consumer() is not Send.

Quite new to asynchronous programming, and I can't wrap my head around this compiler error:

`future returned by \`run_consumer` is not `Send``


`= help: the trait \`Sync` is not implemented for `dyn consumer::Consumer``

`note: future is not \`Send` as this value is used across an await`

`--> src/consumer/mod.rs:30:31`


`30 | consumer.consume(html).await;`

`| -------- ^^^^^^ await occurs here, with \`consumer` maybe used later`

`| |`

`| has type \`&dyn consumer::Consumer` which is not `Send``

I get the error when doing the following in my main.rs:

`let tokio_runtime = Builder::new_multi_thread().enable_all().build().unwrap();`
`// Start the consumer`
`tokio_runtime.spawn(async move { run_consumer(result_receiver, true) });`

What are the potential solutions here? Moreover, why do I get the error in the first place ?

Your equivalent SO post: rust - Future returned by run_consumer() is not Send - Stack Overflow was closed because it needs more details. Without the body of run_consumer we don't know why your future isn't send/why you can't use consumer across await points. So if you could provide a minimal reproducible example, it would greatly enhance our ability to help you and consequently your chances of getting a satisfying solution for your problem.

Trait objects don't automatically expose Send/Sync impls. It looks like you're holding a reference to a trait object across an await point, which means the trait object needs to explicitly be dyn consumer::Consumer + Sync

Thanks for taking the time out. This worked!

Apologies if the question seemed lacking in detail. Luckily I still managed to get an answer from the good people in TRPL discord server. Thanks for all your help!