Attribute Macro shuttle_service::main

source · []
#[main]
Expand description

Helper macro that generates the entrypoint required by any service - likely the only macro you need in this crate.

Without shuttle managed resources

The simplest usage is when your service does not require any shuttle managed resources, so you only need to return a shuttle supported service:

use shuttle_service::ShuttleRocket;

#[shuttle_service::main]
async fn rocket() -> ShuttleRocket {
    let rocket = rocket::build();

    Ok(rocket)
}

shuttle supported services

The following types can be returned from a #[shuttle_service::main] function and enjoy first class service support in shuttle. Be sure to also enable the correct feature on shuttle-service in Cargo.toml for the type to be recognized.

Return typeFeature flagServiceVersionExample
ShuttleRocketweb-rocketrocket0.5.0-rc.2GitHub
ShuttleAxumweb-axumaxum0.5GitHub
ShuttleSalvoweb-salvosalvo0.34.3GitHub
ShuttleTideweb-tidetide0.16.0GitHub
ShuttlePoemweb-poempoem1.3.35GitHub
Result<T, shuttle_service::Error>web-towertower0.14.12GitHub
ShuttleSerenitybot-serenityserenity0.11.5GitHub

Getting shuttle managed resources

Shuttle is able to manage resource dependencies for you. These resources are passed in as inputs to your #[shuttle_service::main] function and are configured using attributes:

use sqlx::PgPool;
use shuttle_service::ShuttleRocket;

struct MyState(PgPool);

#[shuttle_service::main]
async fn rocket(#[shuttle_shared_db::Postgres] pool: PgPool) -> ShuttleRocket {
    let state = MyState(pool);
    let rocket = rocket::build().manage(state);

    Ok(rocket)
}

More shuttle managed resources can be found here