error[E0507]: cannot move out of `mysql`, a captured variable in an `FnMut` closure
--> src/main.rs:1357:26
|
1320 | let mysql = web::Data::new(MySQL {
| ----- captured outer variable
...
1356 | Job::new_async("1/15 * * * * *", |uuid, mut l| {
| ------------- captured by this `FnMut` closure
1357 | Box::pin(async move {
| __________________________^
1358 | | route_handlers::invoices::restaurant_invoice_creator(mysql).a...
| | -----
| | |
| | variable moved due to use in generator
| | move occurs because `mysql` has type `actix_web::web::Data<MySQL>`, which does not implement the `Copy` trait
1359 | | })
| |_________________^ `mysql` is moved here
I am also using the mysql variable for the Actix web server:
HttpServer::new(move || {
let cors = Cors::default().allow_any_origin();
App::new()
.app_data(web::Data::clone(&mysql))
//...
error[E0507]: cannot move out of `mysql_clone`, a captured variable in an `FnMut` closure
--> src/main.rs:1353:26
|
1348 | let mysql_clone = mysql.clone();
| ----------- captured outer variable
...
1352 | Job::new_async("1/15 * * * * *", |uuid, mut l| {
| ------------- captured by this `FnMut` closure
1353 | Box::pin(async move {
| __________________________^
1354 | | route_handlers::invoices::restaurant_invoice_creator(mysql_clone).await;
| | -----------
| | |
| | variable moved due to use in generator
| | move occurs because `mysql_clone` has type `actix_web::web::Data<MySQL>`, which does not implement the `Copy` trait
1355 | | })
| |_________________^ `mysql_clone` is moved here
You didn't provide the full code, so this is my guess:
FnMut closure is supposed to be called multiple times, but takes the ownership of mysql inside, so the closure actually can't be called multiple times.
So the solution is apparent:
use FnOnce as the trait bound if you don't need it to be called multiple times
or let the value captured by reference in FnMut closure