#[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_rocket::ShuttleRocket;
#[shuttle_rocket::main]
async fn rocket() -> ShuttleRocket {
let rocket = rocket::build();
Ok(rocket.into())
}
§Shuttle supported services
The following types can be returned from a #[shuttle_service::main]
function and enjoy first class service support in shuttle.
Return type | Crate | Service | Version | Example |
---|---|---|---|---|
ShuttleActixWeb | shuttle-actix-web | actix-web | 4.3 | GitHub |
ShuttleAxum | shuttle-axum | axum | 0.7 | GitHub |
ShuttlePoem | shuttle-poem | poem | 2.0 | GitHub |
ShuttleRocket | shuttle-rocket | rocket | 0.5 | GitHub |
ShuttleSalvo | shuttle-salvo | salvo | 0.63 | GitHub |
ShuttleSerenity | shuttle-serenity | serenity and poise | 0.12 | GitHub |
ShuttleThruster | shuttle-thruster | thruster | 1.3 | GitHub |
ShuttleTower | shuttle-tower | tower | 0.4 | GitHub |
ShuttleTide | shuttle-tide | tide | 0.16 | GitHub |
§Getting shuttle managed resources
Shuttle is able to manage resource dependencies for you. These resources are passed in as inputs to your #[shuttle_runtime::main]
function and are configured using attributes:
use sqlx::PgPool;
use shuttle_rocket::ShuttleRocket;
struct MyState(PgPool);
#[shuttle_runtime::main]
async fn rocket(#[shuttle_shared_db::Postgres] pool: PgPool) -> ShuttleRocket {
let state = MyState(pool);
let rocket = rocket::build().manage(state);
Ok(rocket.into())
}