Skip to main content

main

Attribute Macro main 

Source
#[main]
Expand description

#[rustango::main] — the runserver entrypoint. Wraps #[tokio::main] and a default tracing_subscriber initialisation (env-filter, falling back to info,sqlx=warn) so user main functions are zero-boilerplate. RUST_LOG and RUSTANGO__LOGGING__FORMAT (e.g. json) come from the real environment, else from ./.env (only those keys are read):

ⓘ
#[rustango::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    rustango::server::Builder::from_env().await?
        .migrate("migrations").await?
        .api(my_app::urls::api())
        .seed_with(my_app::seed::run).await?
        .serve("0.0.0.0:8080").await
}

Optional flavor = "current_thread" passes through to #[tokio::main]; default is the multi-threaded runtime.

logging = false suppresses the default subscriber, for apps that install their own. Needed whenever the body reaches Cli::with_logging() or logging::Setup: the subscriber this macro installs gets there first, and tracing keeps the first one, so the [logging] section would otherwise be read and discarded (#1465).

ⓘ
#[rustango::main(logging = false)]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    rustango::manage::Cli::new()
        .with_settings_from_env()
        .with_logging()          // now the first installer
        .run().await
}

Pulls tracing-subscriber into the rustango crate behind the runtime sub-feature (implied by tenancy), so apps that opt out get plain #[tokio::main] ergonomics without the dependency.