Skip to main content

main

Attribute Macro main 

Source
#[main]
Expand description

Generates the application entry point from an async main function.

The decorated function must be named main, be async, and accept exactly two parameters: an AppBuilder and a config type that implements serde::de::DeserializeOwned + Default.

The macro replaces the function with a sync fn main() that:

  • builds a multi-threaded Tokio runtime,
  • initialises tracing_subscriber using RUST_LOG, falling back to "info,sqlx::query=warn" when the environment variable is unset,
  • loads the config via modo::config::load_or_default,
  • runs the async body, and
  • exits with code 1 if an error is returned.

The return type annotation on the async fn main is not enforced by the macro; the body is wrapped in an internal Result<(), Box<dyn std::error::Error>>.

§Optional attribute

static_assets = "path/" — embeds the given folder as static files using rust_embed. Requires the static-embed feature on modo-macros.