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 services
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 rocket::{Build, Rocket};
#[shuttle_service::main]
async fn rocket() -> Result<Rocket<Build>, shuttle_service::Error> {
let rocket = rocket::build();
Ok(rocket)
}
shuttle supported services
The following type can take the place of the Ok
type and enjoy first class service support in shuttle. Be sure to also enable the feature on
shuttle-service
in Cargo.toml
for the type to be recognized.
Ok type | Feature flag | Service | Version | Example |
---|---|---|---|---|
Rocket<Build> | web-rocket | rocket | 0.5.0-rc.1 | GitHub |
SyncWrapper<Router> | web-axum | axum | 0.5 | GitHub |
Server<T> | web-tide | tide | 0.16.0 | GitHub |
Getting shuttle managed services
The shuttle is able to manage service dependencies for you. These services are passed in as inputs to your main function:
use rocket::{Build, Rocket};
use sqlx::PgPool;
struct MyState(PgPool);
#[shuttle_service::main]
async fn rocket(pool: PgPool) -> Result<Rocket<Build>, shuttle_service::Error> {
let state = MyState(pool);
let rocket = rocket::build().manage(state);
Ok(rocket)
}
shuttle managed dependencies
The following dependencies can be managed by shuttle - remember to enable their feature flags for the shuttle-service
dependency in Cargo.toml
: