Attribute Macro rocket::main[][src]

Expand description

Retrofits async fn support in main functions.

A main async fn function decorated with #[rocket::main] is transformed into a regular main function that internally initializes a Rocket-specific tokio runtime and runs the attributed async fn inside of it:

async fn main() -> Result<(), rocket::Error> {

It should be used only when inspection of an ignited instance of Rocket is required, or when the return value of launch() is to be inspected:

async fn main() -> Result<(), rocket::Error> {
    let rocket = rocket::build().ignite().await?;
    println!("Hello, Rocket: {:?}", rocket);

    let result = rocket.launch().await;
    println!("The server shutdown: {:?}", result);


For all other cases, use #[launch] instead.

The function attributed with #[rocket::main] must be async and must be called main. Violation of either results in a compile-time error.