1

I am using rust rocket rocket = { version = "=0.5.0-rc.2", features = ["json"] } as my web server, today I found there is two way to start the rocket, one of the start like this:

#[rocket::main]
async fn main() {
    // the rocket start logic
}

the other way look like this:

#[launch]
async fn rocket() -> _ {
    // the rocket start logic
}

which one style should I use? which one is better? what should I learn from the two startup style? I am search from google but no one talk about this.

Dolphin
  • 29,069
  • 61
  • 260
  • 539

1 Answers1

1

As stated in the documentation, #[rocket::main]

should be used only when the return values of ignite() or launch() are to be inspected

If you use rust-analyzer #[rocket::main] is reliably discovered as the main function which brings the added benefit, that convenient Debug and Run buttons are displayed above the function.

For production it would however be recommended to use the #[launch] attribute.

frankenapps
  • 5,800
  • 6
  • 28
  • 69