Skip to content

Sync in handler, future cannot be sent between threads safely #1708

Answered by allan2
allan2 asked this question in Q&A
Discussion options

You must be logged in to vote

I got it working. I had read the solution but forgot to actually cast.

Changed this:

let mut params = Vec::<Box<dyn ToSql + Sync + Send>>::with_capacity(4);  // add Send

and this

let params = params
    .iter()
    .map(|x| x.as_ref() as &(dyn ToSql + Sync))  // need to cast
    .collect::<Vec<_>>();

and now it works.

Thanks for Axum!

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by allan2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants