我有这个代码
#[api_operation(
tag = "image",
summary = "uploads an image",
description = r###"upload an image to an account"###,
error_code = 405
)]
pub async fn upload_image(mut payload: Multipart) -> impl Responder {
let upload_dir = std::env::var("UPLOAD_DIR").unwrap_or_else(|_| "./uploads".to_string());
let upload_status = files::save_file(payload, format!("{upload_dir}/test.png").to_string()).await;
对我来说这看起来像是一个
async
方法。
但由于某种原因我遇到编译错误
error[E0728]: `await` is only allowed inside `async` functions and blocks
--> src/image.rs:18:97
|
9 | / #[api_operation(
10 | | tag = "image",
11 | | summary = "uploads an image",
12 | | description = r###"upload an image to an account"###,
13 | | error_code = 405
14 | | )]
| |__- this is not `async`
...
18 | let upload_status = files::save_file(payload, format!("{upload_dir}/test.png").to_string()).await;
| ^^^^^ only allowed inside `async` functions and blocks
是说宏导致它不是异步的,还是为什么我不能使用await?
有什么办法可以解决吗?