Crate async_main

source ·
Expand description

Runtime-agnostic async main proc macro. Currently, this crate only supports single-threaded task pools, but in a future version will add a configuration option to enable multi-threaded task pools.

Async Executor (with futures-lite)

use std::sync::Arc;

use async_executor::LocalExecutor;
use async_main::async_main;

#[async_main(async_executor)]
async fn main(_executor: Arc<LocalExecutor<'_>>) {
    println!("Hello, world!");
}

Async Std

use async_main::async_main;

#[async_main(async_std)]
async fn main(_executor: ()) {
    println!("Hello, world!");
}

Futures

use async_main::async_main;
use futures::executor::LocalSpawner;

#[async_main(futures)]
async fn main(_executor: LocalSpawner) {
    println!("Hello, world!");
}

Pasts

use async_main::async_main;
use pasts::prelude::*;

#[async_main(pasts)]
async fn main(_executor: Executor) {
    println!("Hello, world!");
}

Smolscale

use async_main::async_main;

#[async_main(smolscale)]
async fn main(_executor: ()) {
    println!("Hello, world!");
}

Tokio

use std::sync::Arc;

use async_main::async_main;
use tokio::runtime::Runtime;

#[async_main(tokio)]
async fn main(_executor: Arc<Runtime>) {
    println!("Hello, world!");
}

Attribute Macros

Mark the entry point of the program.