What am I missing that makes this undesirable?
What am I missing that makes this undesirable?
If you run any implicit eventloop, that property would no longer be given.
Next, it wouldn't even be desirable for lots of applications. Async IO and functions are not necessarily be faster than synchronous operations - it might as well the opposite if you don't have a lot of concurrency. E.g. if you read from one blocking socket, you do a single `read()` syscall. Add async IO, and you need an additional `select/epoll_wait` call.
Then there is an actual cost for composing Futures which are large values on the stack, sometimes having to box them (since otherwise recursion won't work and dynamic dispatch will neither, etc). The latter might certainly be avoidable with a different kind of "async design" than what Rust currently has, but there will always be some tradeoffs.
> calling the code that calls main(), runs functions registered on executable load, registered atexit(), soft floating point emulation, running constructors/destructors on start/exit, handling exceptions, threading support.
You call main() (or whatever) from your reset handler, there is no "executable load", there is no "atexit()", floating point can be hard-instructions (if available), call __libc_init_array() to call constructors if required, you usually don't use exception handling, and of course there is no threading support.
Perhaps you can call "runtime" the instructions inserted to call constructors/destructors but I think it doesn't qualify.
The embedded use of C and C++ dialects rely on compiler specific extensions and are per ISO standard implementation-defined, without any guarantee of code portability as per freestanding definition.
If you're using `async_std`, right now you simply, explicitly, introduce the runtime:
let fut = async_fn();
let res = async_std::task::block_on(fut)?;
(pulling out the Future into fut is just illustrative, it can of course be a single line) instead of: let res = async_fn().await?;
So it's already pretty darn easy to do what you want.Also, here's an easy way to make it feel like a keyword:
use std::result::Result;
use std::error::Error;
use async_std::task::block_on as block;
fn main() -> Result<(), Box<dyn Error>> {
let fut = async_std::fs::read_to_string("./Cargo.toml");
let file = block(fut)?;
println!("{}", file);
Ok(())
}
---
[package]
name = "async-sandbox"
version = "0.1.0"
edition = "2018"
[dependencies]
async-std = "1.10"
One final thing to point out here is that, unlike some other languages, in Rust you can call any async function just like any normal function. The only thing that requires a runtime is resolving the returned future. So it's not so much that functions are colored but that resolving futures needs a runtime and there is none in the current standard lib.If you want the full gory details: https://github.com/rust-lang/rust/pull/65875
(I personally would like a very very simple one like the ten LOC version, but wouldn’t want anything more.)
It did not work that well, as not everyone is confortable in an async only world.