Okay but this is my actual code:
async fn order_form(mysql: web::Data<MySQL>, form: web::Form<OrderForm>, req: HttpRequest, mollie: web::Data<mollie::Mollie>) -> String {
let mut client = Client {
id: 0,
firstname: form.firstname.to_string(),
lastname: form.lastname.to_string(),
email: form.from_email.to_string(),
tel: form.tel.to_string(),
saved_account: false,
};
let distributor = data::get_distributor_by_subdomain(&mysql, get_subdomain_part(req.headers().get("Host").unwrap().to_str().unwrap())).await.unwrap();
let distributor_voucher = data::get_distributor_voucher(&mysql, form.voucher).await.unwrap();
let client_id = data::add_client(&mysql, &client).await;
client.id = client_id;
let mut sale = Sale {
id: 0,
client: client,
payment_id: "".to_string(),
paid: false,
};
let balance = distributor_voucher.amount;
let sale_id = data::add_sale(&mysql, &sale).await;
sale.id = sale_id;
let mut payment_id = "".to_string(); // payment_id is passed by reference and gets a new value
let payment_url = mollie.make_payment(&data::get_sale(&mysql, data::ByIdOrPaymentId::ById(sale_id)).await.unwrap(), &mut payment_id).await;
let mut voucher = Voucher {
id: 0,
sale: sale,
distributor: distributor,
receiver: form.to_email.to_string(),
distributorvoucher: distributor_voucher,
balance: balance,
one_use_only: true,
used: false,
expiration_date: format!("2021-01-01 00:00:00+01:00").parse().unwrap(),
hash_code: "hashcode".to_string(),
number_code: "0101-020".to_string(),
};
data::add_voucher(&mysql, &voucher).await;
let mut sale2 = sale;
sale2.payment_id = payment_id;
data::update_sale(&mysql, &sale2, data::ByIdOrPaymentId::ById(sale_id)).await;
payment_url
}
Error
error[E0382]: use of moved value: `sale`
--> src/main.rs:622:21
|
588 | let mut sale = Sale {
| -------- move occurs because `sale` has type `Sale`, which does not implement the `Copy` trait
...
606 | sale: sale,
| ---- value moved here
...
622 | let mut sale2 = sale;
| ^^^^ value used here after move
A simple change of order won't help me I guess.