Skip to content

Commit 27135e1

Browse files
authored
Add a note on async trait (#558)
1 parent 2db1f14 commit 27135e1

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/async/pitfalls/async-traits.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,16 @@ async fn main() {
4848

4949
<details>
5050

51+
* The difficulty with `async trait` is in that the resulting `Future` does not
52+
have a size known at compile time, because the size of the `Future` depends
53+
on the implementation.
54+
5155
* `async_trait` is easy to use, but note that it's using heap allocations to
52-
achieve this, which has performance implications.
56+
achieve this, and solve the unknow size problem above. This heap allocation
57+
has performance overhead.
5358

54-
* Try creating a new sleeper struct that will sleep for a random amount of time and adding it to the Vec.
59+
* Try creating a new sleeper struct that will sleep for a random amount of time
60+
and adding it to the Vec.
5561

5662
* Try making the `sleep` call take `&mut self`.
5763

0 commit comments

Comments
 (0)