Skip to content

Commit

Permalink
Merge pull request #255 from dtolnay/asyncblock
Browse files Browse the repository at this point in the history
Update explanation to show async block expansion
  • Loading branch information
dtolnay authored Dec 30, 2023
2 parents 3caf301 + 381fd75 commit 3c656d3
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 3c656d3

Please sign in to comment.