when I using this command cargo build to compile the rust project, shows error like this:
➜ reddwarf-admin git:(main) ✗ cargo build
Compiling reddwarf-admin v0.1.0 (/Users/xiaoqiangjiang/source/reddwarf/backend/reddwarf-admin)
error: the `async` keyword is missing from the function declaration
--> src/main.rs:48:7
|
48 | async fn main() {
| ^^
this is my fn function look like:
#[rocket::main]
#[tokio::main]
async fn main() {
tokio::spawn(refresh_channel_rep());
tokio::spawn(refresh_channel_article_count());
tokio::spawn(remove_low_quality_articles());
tokio::spawn(calculate_article_trend());
let launch_result = create_server().launch().await;
match launch_result {
Ok(_) => println!("Rocket shut down gracefully."),
Err(err) => println!("Rocket had an error: {}", err),
};
}
I have already tried to add the tokio micro in the main.rs like this:
#[macro_use]
extern crate tokio;
the problem still did not solved, why did this happen? what should I do to fixed this problem?
>Solution :
You shouldn’t use both #[rocket::main] and #[tokio::main], since the first does strictly more then the second – tokio::main just starts the runtime, rocket::main does the same and also configures it according to the Rocket configuration.
Just use the #[rocket::main] only, and everything should work.