# Braking Async Main and Test in rustc in pieces from tokio
## Overview
- Introduction
- Pieces of Tokio
## Introduction
From out previous chat in [zulip](https://rust-lang.zulipchat.com/#narrow/stream/187312-wg-async/topic/Weekly.20sync.202022-12-15) we talk about the content [in the notes](https://hackmd.io/@vincenzopalazzo-rust/SJkBzhJOo)
Some of the open question is how Tokio expand the macros on top of the main function, and tests,
so I make some research and this is the result
The following rust code
```rust!
#[tokio::main]
async fn main() {
println!("Hello, world!");
}
```
Will be expanded in
```rust!
use std::prelude::rust_2021::*;
#[macro_use]
extern crate std;
fn main() {
let body = async {
{
::std::io::_print(format_args!("Hello, world!\n"));
};
};
#[allow(clippy::expect_used, clippy::diverging_sub_expression)]
{
return tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
.expect("Failed building the Runtime")
.block_on(body);
}
}
```
Regarding the tests, the following code
```rust!
#[cfg(test)]
mod tests {
#[tokio::test]
async fn it_works() {
let result = 2 + 2;
assert_eq!(result, 4);
}
}
```
will expand to the following code
```rust!
#[cfg(test)]
mod tests {
extern crate test;
#[cfg(test)]
#[rustc_test_marker = "tests::it_works"]
pub const it_works: test::TestDescAndFn = test::TestDescAndFn {
desc: test::TestDesc {
name: test::StaticTestName("tests::it_works"),
ignore: false,
ignore_message: ::core::option::Option::None,
compile_fail: false,
no_run: false,
should_panic: test::ShouldPanic::No,
test_type: test::TestType::UnitTest,
},
testfn: test::StaticTestFn(|| test::assert_test_result(it_works())),
};
fn it_works() {
let body = async {
let result = 2 + 2;
match (&result, &4) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(
kind,
&*left_val,
&*right_val,
::core::option::Option::None,
);
}
}
};
};
let mut body = body;
#[allow(unused_mut)]
let mut body = unsafe {
::tokio::macros::support::Pin::new_unchecked(&mut body)
};
let body: ::std::pin::Pin<&mut dyn ::std::future::Future<Output = ()>> = body;
#[allow(clippy::expect_used, clippy::diverging_sub_expression)]
{
return tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("Failed building the Runtime")
.block_on(body);
}
}
}
```
## Pieces of Tokio
So, Tokio implement a Runtime Interface that looks like
the following one
```rust!
```