Rollup merge of #119222 - eholk:into-async-iterator, r=compiler-errors,dtolnay
Add `IntoAsyncIterator` This introduces the `IntoAsyncIterator` trait and uses it in the desugaring of the unstable `for await` loop syntax. This is mostly added for symmetry with `Iterator` and `IntoIterator`. r? `@compiler-errors` cc `@rust-lang/libs-api,` `@rust-lang/wg-async`
This commit is contained in:
@@ -135,3 +135,26 @@ impl<T> Poll<Option<T>> {
|
||||
#[lang = "AsyncGenFinished"]
|
||||
pub const FINISHED: Self = Poll::Ready(None);
|
||||
}
|
||||
|
||||
/// Convert something into an async iterator
|
||||
#[unstable(feature = "async_iterator", issue = "79024")]
|
||||
pub trait IntoAsyncIterator {
|
||||
/// The type of the item yielded by the iterator
|
||||
type Item;
|
||||
/// The type of the resulting iterator
|
||||
type IntoAsyncIter: AsyncIterator<Item = Self::Item>;
|
||||
|
||||
/// Converts `self` into an async iterator
|
||||
#[cfg_attr(not(bootstrap), lang = "into_async_iter_into_iter")]
|
||||
fn into_async_iter(self) -> Self::IntoAsyncIter;
|
||||
}
|
||||
|
||||
#[unstable(feature = "async_iterator", issue = "79024")]
|
||||
impl<I: AsyncIterator> IntoAsyncIterator for I {
|
||||
type Item = I::Item;
|
||||
type IntoAsyncIter = I;
|
||||
|
||||
fn into_async_iter(self) -> Self::IntoAsyncIter {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,5 +124,5 @@
|
||||
mod async_iter;
|
||||
mod from_iter;
|
||||
|
||||
pub use async_iter::AsyncIterator;
|
||||
pub use async_iter::{AsyncIterator, IntoAsyncIterator};
|
||||
pub use from_iter::{from_iter, FromIter};
|
||||
|
||||
Reference in New Issue
Block a user