#[main]
Expand description
Main function attribute macro for fastn applications with context support.
This macro transforms your async main function to automatically set up the tokio runtime and initialize global context management. It’s the recommended way to start fastn applications.
§Features
- Automatically creates a multi-threaded tokio runtime
- Enables all tokio features (time, net, fs, etc.)
- Sets up global context management
- Provides clean error handling
§Example
use fastn_context::main;
#[main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("Application starting");
// Global context is available
let ctx = fastn_context::global().await;
println!("App context: {}", ctx.name());
Ok(())
}
§Return Types
Your main function can return:
()
- No error handlingResult<(), E>
whereE: std::error::Error
- With error handling
§Generated Code
The macro generates a standard fn main()
that creates the tokio runtime and calls
your async function. Error handling is automatically provided.