You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: posts/inside-rust/2022-11-17-async-fn-in-trait-nightly.md
+4-6Lines changed: 4 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -106,12 +106,10 @@ Besides, users [expect][alan-async-traits] to be able to write `async fn` in tra
106
106
107
107
Traits that need to work with zero overhead or in no_std contexts have another option: they can take the concept of polling from the [`Future` trait](https://doc.rust-lang.org/stable/std/future/trait.Future.html) and build it directly into their interface. The `Future::poll` method returns `Poll::Ready(Output)` if the future is complete and `Poll::Pending` if the future is waiting on some other event.
108
108
109
-
You can see this pattern, for example, in the Stream[^stream-futures] trait. The signature of `Stream::poll_next` is a cross between `Future::poll` and `Iterator::next`.
110
-
111
-
[^stream-futures]: The [`Stream` trait](https://docs.rs/futures/latest/futures/stream/trait.Stream.html) is part of the `futures` crate, not the standard library.
109
+
You can see this pattern, for example, in the current version of the unstable [AsyncIterator](https://doc.rust-lang.org/stable/std/async_iter/trait.AsyncIterator.html) trait. The signature of `AsyncIterator::poll_next` is a cross between `Future::poll` and `Iterator::next`.
112
110
113
111
```rust
114
-
pubtraitStream {
112
+
pubtraitAsyncIterator {
115
113
typeItem;
116
114
117
115
fnpoll_next(
@@ -143,7 +141,7 @@ impl Database for MyDb {
143
141
}
144
142
```
145
143
146
-
One thing this will allow us to do is standardize new traits we've been waiting on this feature for. For example, the `Stream` trait from above is significantly more complicated than its analogue, `Iterator`. With the new support, we can simply write this instead:
144
+
One thing this will allow us to do is standardize new traits we've been waiting on this feature for. For example, the `AsyncIterator` trait from above is significantly more complicated than its analogue, `Iterator`. With the new support, we can simply write this instead:
147
145
148
146
```rust
149
147
#![feature(async_fn_in_trait)]
@@ -154,7 +152,7 @@ trait AsyncIterator {
154
152
}
155
153
```
156
154
157
-
There's a decent chance that exactly this trait will end up in the standard library! For now though, you can use the one in the [`async_iterator` crate](https://docs.rs/async-iterator/latest/async_iterator/) and write generic code with it, just like you would normally.
155
+
There's a decent chance that the trait in the standard library will end up exactly like this! For now, you can also use the one in the [`async_iterator` crate](https://docs.rs/async-iterator/latest/async_iterator/) and write generic code with it, just like you would normally.
0 commit comments