Content-Length: 13477 | pFad | https://doc.rust-lang.org/std/pin/../hash/../../std/sync/../../../std/../error_codes/./E0733.html

E0733 - Error codes index

Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Error code E0733

An async function used recursion without boxing.

Erroneous code example:

#![allow(unused)]
fn main() {
async fn foo(n: usize) {
    if n > 0 {
        foo(n - 1).await;
    }
}
}

The recursive invocation can be boxed:

#![allow(unused)]
fn main() {
async fn foo(n: usize) {
    if n > 0 {
        Box::pin(foo(n - 1)).await;
    }
}
}

The Box<...> ensures that the result is of known size, and the pin is required to keep it in the same place in memory.

Alternatively, the body can be boxed:

#![allow(unused)]
fn main() {
use std::future::Future;
use std::pin::Pin;
fn foo(n: usize) -> Pin<Box<dyn Future<Output = ()>>> {
    Box::pin(async move {
        if n > 0 {
            foo(n - 1).await;
        }
    })
}
}








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://doc.rust-lang.org/std/pin/../hash/../../std/sync/../../../std/../error_codes/./E0733.html

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy