---
source: https://iinventedlight.com/library/notes/rust-tokio-main-macro.md
title: "#[tokio::main] turns async fn main into a sync main that starts a Tokio runtime"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "MIT (Tokio tutorial); MIT (tokio-rs/website (GitHub)); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Tokio tutorial, Hello Tokio; tokio-rs/website (GitHub), hello-tokio.md (source page). MIT (https://raw.githubusercontent.com/tokio-rs/website/master/LICENSE). Copyright Tokio contributors."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-18
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-18
as_of: 2026-11-18
confidence: medium
untested: "Not reproduced (2026-11-18). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-systems: tokio main macro"
tags: [rust, tokio, async, runtime, tokio-main, futures]
client: Librarian
sources:
  - id: S1
    title: "Hello Tokio"
    publisher: Tokio tutorial
    url: https://tokio.rs/tokio/tutorial/hello-tokio
    accessed: 2026-11-18
    license: "MIT"
  - id: S2
    title: "hello-tokio.md (source page)"
    publisher: tokio-rs/website (GitHub)
    url: https://github.com/tokio-rs/website/blob/master/content/tokio/tutorial/hello-tokio.md
    accessed: 2026-11-18
    license: "MIT"
---
# #[tokio::main] turns async fn main into a sync main that starts a Tokio runtime
**Answer:** Annotate `async fn main` with `#[tokio::main]`. Asynchronous functions must be executed by a runtime, and the runtime does not automatically start; the macro transforms the async main into a synchronous `fn main()` that initializes a runtime instance and executes the async body.

## What the macro expands to

```rust
#[tokio::main]
async fn main() {
    println!("hello");
}

// becomes roughly:
fn main() {
    let mut rt = tokio::runtime::Runtime::new().unwrap();
    rt.block_on(async {
        println!("hello");
    })
}
```

## Dependency

```toml
[dependencies]
tokio = { version = "1", features = ["full"] }
```
The tutorial enables the `full` feature flag; Tokio has a lot of functionality behind feature flags.

## Async functions are lazy

Calling an async fn does not execute its body. An async fn returns an anonymous type that implements the `Future` trait, and the operation runs only when you use the `.await` operator on it:

```rust
async fn say_world() { println!("world"); }

#[tokio::main]
async fn main() {
    let op = say_world();   // nothing printed yet
    println!("hello");
    op.await;               // prints "world"
}
```
That program outputs `hello` then `world`.

## What the runtime provides

The runtime contains the asynchronous task scheduler, provides evented I/O, timers, etc. An async fn is used for main because we want to enter an asynchronous context.

## See also

- [rust-async-await-futures](https://iinventedlight.com/library/notes/rust-async-await-futures/)
- [rust-tokio-spawn](https://iinventedlight.com/library/notes/rust-tokio-spawn/)
- [rust-cargo-new-project](https://iinventedlight.com/library/notes/rust-cargo-new-project/)

## Claims

- id: C1
  claim: The macro transforms async main into a synchronous main.
  source: S1
  evidence: "It transforms the async fn main() into a synchronous fn main()"

- id: C2
  claim: The runtime does not start automatically.
  source: S1
  evidence: "The runtime does not automatically start"

- id: C3
  claim: The runtime contains the task scheduler.
  source: S2
  evidence: "The runtime contains the asynchronous task scheduler"

## Sources

- [S1] Hello Tokio. Tokio tutorial. https://tokio.rs/tokio/tutorial/hello-tokio . License: MIT. Accessed 2026-11-18.

- [S2] hello-tokio.md (source page). tokio-rs/website (GitHub). https://github.com/tokio-rs/website/blob/master/content/tokio/tutorial/hello-tokio.md . License: MIT. Accessed 2026-11-18.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Tokio tutorial, Hello Tokio; tokio-rs/website (GitHub), hello-tokio.md (source page). MIT (https://raw.githubusercontent.com/tokio-rs/website/master/LICENSE). Copyright Tokio contributors. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
