News for hackers. Stuff that matters.
Re:A four year plan for async Rust by wavemode on Tuesday November 07, 2023 @12:48PM (#38180177)
The complexity of this code snippet almost seems satirical (though I do get the point you're making, and agree with you).
Re:A four year plan for async Rust by dymk on Tuesday November 07, 2023 @12:53PM (#38180257)
On one hand, I agree that on the surface, this looks complex, if you don't read it.

But on the other hand, just read the code. It's not complex.

You drill down into a tokio namespace. You make a builder object. You unwrap it. This is idiomatic Rust. It's verbose, but explicit is better than vague. There's no conditional logic. There's no weird type-fu. No macros. There's not even any parameters to supply, other than the Future to block on.

It's trivial to write a wrapper to go from chained methods a helper call.

Re:A four year plan for async Rust by lenkite on Thursday November 09, 2023 @02:53AM (#38202251)
The next time a Rust fan pokes fun about Java's verbosity, I am copy-pasting that.
Re:A four year plan for async Rust by mplanchard on Tuesday November 07, 2023 @12:58PM (#38180362)
Just noting for other readers that, while killercup posted another option using `smol`, this seems to me to be in line with Rust's philosophy of explicitness, which is something I really appreciate about the language:

- create a builder

- run on the current thread only

- enable all drivers

- create the instance

- ignore errors

- then call some blocking async code

Would look nicer if split out onto multiple lines I imagine:

    use tokio::runtime::Builder;

    let runtime = Builder::new_current_thread()
        .enable_all()
        .build()?;

    runtime.block_on(async { println!("I'm async!"); });