Skip to content

Commit

Permalink
Update explanation to show async block expansion
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Dec 30, 2023
1 parent 3caf301 commit 381fd75
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ can't be that badly broken.
## Explanation

Async fns get transformed into methods that return `Pin<Box<dyn Future + Send +
'async_trait>>` 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:
Expand All @@ -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))
})
}
}
```
Expand Down
8 changes: 3 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
//! # Explanation
//!
//! Async fns get transformed into methods that return `Pin<Box<dyn Future +
//! Send + 'async_trait>>` 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:
Expand All @@ -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))
//! })
//! }
//! }
//! # };
Expand Down

0 comments on commit 381fd75

Please sign in to comment.