8000 Add post for 1.77 by Mark-Simulacrum · Pull Request #1271 · rust-lang/blog.rust-lang.org · GitHub
[go: up one dir, main page]

Skip to content

Conversation

Mark-Simulacrum
Copy link
Member

cc @rust-lang/release

Mark-Simulacrum and others added 3 commits March 10, 2024 19:58
Co-authored-by: Kevin Reid <kpreid@switchb.org>
Co-authored-by: Eric Huss <eric@huss.org>
Co-authored-by: Kevin Reid <kpreid@switchb.org>
@lcnr
Copy link
Contributor
lcnr commented Mar 11, 2024

I think one of the biggest changes in 1.77 is rust-lang/rust#117703.

We now support recursive async functions (as long as they use indirection), making the async-recursion crate unnecessary.

before:

use async_recursion::async_recursion;

#[async_recursion]
async fn fib(n : u32) -> u32 {
   match n {
      0 | 1 => 1,
      _ => fib(n-1).await + fib(n-2).await
   }
}
// which expands to
use std::future::Future;
use std::pin::Pin;

fn fib(n: u32) -> Pin<Box<dyn Future<Output = u32> + Send>> {
    Box::pin(async move {
        match n {
            0 | 1 => 1,
            _ => fib(n - 1).await + fib(n - 2).await,
        }
    })
}

after

async fn fib(n : u32) -> u32 {
   match n {
       0 | 1 => 1,
       _ => Box::pin(fib(n-1)).await + Box::pin(fib(n-2)).await
   }
}

By avoiding trait objects this should improve the runtime performance of such functions and avoids the "auto-trait bound" problem of async-recursion by leaking the Send bound (and all other auto traits) automatically.

@slanterns

This comment was marked as duplicate.

@Mark-Simulacrum
Copy link
Member Author

Alright, I think this is now updated per all the feedback here. Thanks!

Co-authored-by: Kevin Reid <kpreid@switchb.org>
Co-authored-by: Josh Stone <cuviper@gmail.com>
Co-authored-by: lcnr <rust@lcnr.de>
@Mark-Simulacrum Mark-Simulacrum merged commit 405e6a1 into rust-lang:master Mar 21, 2024
@Mark-Simulacrum Mark-Simulacrum deleted the 1.77.0 branch March 21, 2024 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants

0