smol_potat_macro

Attribute Macro main

Source
#[main]
Expand description

Enables an async main function.

§Examples

§Dynamic threads

By default, this spawns as many threads as is in the SMOL_THREADS environment variable, or 1 if it is not specified.

#[smol_potat::main]
async fn main() -> std::io::Result<()> {
    Ok(())
}

§Automatic Threadpool

Alternatively, smol_potat::main can used to automatically set the number of threads by adding the auto feature (off by default).

#[smol_potat::main] // with 'auto' feature enabled
async fn main() -> std::io::Result<()> {
    Ok(())
}

§Manually Configure Threads

To manually set the number of threads, add this to the attribute:

#[smol_potat::main(threads=3)]
async fn main() -> std::io::Result<()> {
    Ok(())
}

§Set the crate root

By default smol-potat will use ::smol_potat as its crate root, but you can override this with the crate option:

use smol_potat as other_smol_potat;

#[smol_potat::main(crate = "other_smol_potat")]
async fn main() -> std::io::Result<()> {
    Ok(())
}