I hate #async in #Rust.
I say that after writing 4 toy runtimes for it.

I have a very async-shaped problem and I *still* can't use async for it without ugly hacks.

Lifetime hell is trying to kill me. Will self-referential struct save me or finish the job? Let's find out.

Yeah, I'm riding #no_std , no alloc, why do you ask?

#programming #rustlang #unsafe #jazda

/// A minimal async runtime.
fn run<T>(thread: &mut Pin<&mut impl Future<Output=T>>) -> T {
let waker = Waker::noop();
let mut context = Context::from_waker(waker);
loop {
match thread.as_mut().poll(&mut context) {
Poll::Pending => {},
Poll::Ready(ret) => {
return ret;
},
}
}
}

fn run_fn<T, F: Future<Output=T>>(f: &mut F) -> T {
let mut pf: Pin<&mut F> = pin!(f);
run(&mut pf)
}