Newer answer, applicable for Tokio 0.3.0 and above
The documentation for tokio::main
shows what options it has.
It is quite common to want to start the current-thread runtime, so there is a special option for it:
#[tokio::main(flavor = "current_thread")]
Old answer, applicable for Tokio < 0.3.0
The documentation for tokio::main
shows what options it has:
core_threads=n
- Sets core threads to n (requires rt-threaded feature).
max_threads=n
- Sets max threads to n (requires rt-core or rt-threaded feature).
Thus:
#[tokio::main(core_threads = 1, max_threads = 1)]
async fn main() {
println!("Hello world");
}
If this does not work for whatever your case is, you will have to directly create a runtime as shown in How do I synchronously return a value calculated in an asynchronous Future?.