You can use `block_on` from the futures-lite crate (or from other crates) to synchronously call async functions.
Not using async or async crates is not recommended since most new or updated high quality crates now use async.
Not using async or async crates is not recommended since most new or updated high quality crates now use async.
~> cd tmp\
~/tmp> cargo new futures-test
Created binary (application) `futures-test` package
~/tmp> cd futures-test
~/tmp/futures-test> cargo add futures-lite
Updating crates.io index
Adding futures-lite v1.13.0 to dependencies.
Features:
+ alloc
+ fastrand
+ futures-io
+ memchr
+ parking
+ std
+ waker-fn
~/tmp/futures-test> code .
~/tmp/futures-test> open src\main.rs
use futures_lite::future;
fn main() {
future::block_on(async {
println!("Hello world!");
})
}
~/tmp/futures-test> cargo run
Compiling futures-io v0.3.28
Compiling memchr v2.6.3
Compiling pin-project-lite v0.2.13
Compiling fastrand v1.9.0
Compiling waker-fn v1.1.1
Compiling parking v2.1.1
Compiling futures-core v0.3.28
Compiling futures-lite v1.13.0
Compiling futures-test v0.1.0 (C:\Users\steve\tmp\futures-test)
Finished dev [unoptimized + debuginfo] target(s) in 1.74s
Running `target\debug\futures-test.exe`
Hello world!
11 total dependencies.And like, to be clear, "the few hundred dependencies from tokio" is also misleading. A `cargo add tokio --features full` adds 43 dependencies to your Cargo.lock at the time of writing.