Hi, I was thinking if this thing could get better then Rust would really take the charm and be the one to choose:

You see the Async function(7 th line) , it f*'s everyone up! If this could actually get better most of the developers (we did a survey of c++ guys in the server) and they are actually ready to switch to rust forever if writing this wasn't a brainf** and could get better and easier!!!!

PLEASEE DO IT!!

Async function traits are stable as of 1.85.0: Announcing Rust 1.85.0 and Rust 2024 | Rust Blog

You can't use them with Send bounds yet, but something in that area is planned. It will probably look like this:

where
    F: AsyncFnMut(&mut ClientSession) -> Result<R, String> + Send,
    F(..): Send
1 Like

I haven't learned Rust yet, but that above code can be writen like this now!??!?

Not now. It is planned but not implemented. I'm not saying your problem is solved now; rather, that you don’t need to advocate for it because it’s already in progress.

Until then, you can use a type alias:

type Async<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;

and then

F: FnMut(&mut ClientState) -> Async<'_, Result<R, String>>
3 Likes

isn't that just BoxFuture in futures::future - Rust ?

2 Likes

Yes, it seems like it's the exact same. You can tell how much experience I have with async Rust.

1 Like