From 381fd7564e6d29d6647da1099e12de36136a4a03 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 30 Dec 2023 15:34:18 -0800 Subject: [PATCH] Update explanation to show async block expansion --- README.md | 8 +++----- src/lib.rs | 8 +++----- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 301ce3f..97dbac9 100644 --- a/README.md +++ b/README.md @@ -118,7 +118,7 @@ can't be that badly broken. ## Explanation Async fns get transformed into methods that return `Pin>` and delegate to a private async freestanding function. +'async_trait>>` and delegate to an async block. For example the `impl Advertisement for AutoplayingVideo` above would be expanded as: @@ -131,11 +131,9 @@ impl Advertisement for AutoplayingVideo { where Self: Sync + 'async_trait, { - async fn run(_self: &AutoplayingVideo) { + Box::pin(async move { /* the original method body */ - } - - Box::pin(run(self)) + }) } } ``` diff --git a/src/lib.rs b/src/lib.rs index e2365c3..d7223ca 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -133,7 +133,7 @@ //! # Explanation //! //! Async fns get transformed into methods that return `Pin>` and delegate to a private async freestanding function. +//! Send + 'async_trait>>` and delegate to an async block. //! //! For example the `impl Advertisement for AutoplayingVideo` above would be //! expanded as: @@ -147,11 +147,9 @@ //! where //! Self: Sync + 'async_trait, //! { -//! async fn run(_self: &AutoplayingVideo) { +//! Box::pin(async move { //! /* the original method body */ -//! } -//! -//! Box::pin(run(self)) +//! }) //! } //! } //! # };