pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


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

URL: https://doc.rust-lang.org/std/pin/../default/../rc/../../../std/../error_codes/./E0728.html

css/general.css">

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 E0728

await has been used outside async function or async block.

Erroneous code example:

#![allow(unused)]
fn main() {
use std::pin::Pin;
use std::future::Future;
use std::task::{Context, Poll};

struct WakeOnceThenComplete(bool);

fn wake_and_yield_once() -> WakeOnceThenComplete {
    WakeOnceThenComplete(false)
}

impl Future for WakeOnceThenComplete {
    type Output = ();
    fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> {
        if self.0 {
            Poll::Ready(())
        } else {
            cx.waker().wake_by_ref();
            self.0 = true;
            Poll::Pending
        }
    }
}

fn foo() {
    wake_and_yield_once().await // `await` is used outside `async` context
}
}

await is used to suspend the current computation until the given future is ready to produce a value. So it is legal only within an async context, like an async function or an async block.

#![allow(unused)]
fn main() {
use std::pin::Pin;
use std::future::Future;
use std::task::{Context, Poll};

struct WakeOnceThenComplete(bool);

fn wake_and_yield_once() -> WakeOnceThenComplete {
    WakeOnceThenComplete(false)
}

impl Future for WakeOnceThenComplete {
    type Output = ();
    fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> {
        if self.0 {
            Poll::Ready(())
        } else {
            cx.waker().wake_by_ref();
            self.0 = true;
            Poll::Pending
        }
    }
}

async fn foo() {
    wake_and_yield_once().await // `await` is used within `async` function
}

fn bar(x: u8) -> impl Future<Output = u8> {
    async move {
        wake_and_yield_once().await; // `await` is used within `async` block
        x
    }
}
}
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy