Attribute Macro tokio_macros::main_rt[][src]

#[main_rt]

Marks async function to be executed by selected runtime. This macro helps set up a Runtime without requiring the user to use Runtime or Builder directly.

Function arguments:

Arguments are allowed for any functions aside from main which is special

Usage

Using default

#[tokio::main(flavor = "current_thread")]
async fn main() {
    println!("Hello world");
}

Equivalent code not using #[tokio::main]

fn main() {
    tokio::runtime::Builder::new_current_thread()
        .enable_all()
        .build()
        .unwrap()
        .block_on(async {
            println!("Hello world");
        })
}

NOTE:

If you rename the tokio crate in your dependencies this macro will not work. If you must rename the 0.3 version of tokio because you’re also using the 0.1 version of tokio, you must make the tokio 0.3 crate available as tokio in the module where this macro is expanded.