about summary refs log tree commit diff
diff options
context:
space:
mode:
authorXiretza <xiretza@xiretza.xyz>2022-12-10 09:27:07 +0100
committerXiretza <xiretza@xiretza.xyz>2022-12-10 09:27:07 +0100
commita8b5d4b7f113975e35b1924af608989e0cd620cd (patch)
tree9cb1013ff36c0ef5b4ccefe84bf4a3578d1d5565
parent0d5573e6daf99a5b98ace3dfcc4be2eb64867169 (diff)
downloadrust-a8b5d4b7f113975e35b1924af608989e0cd620cd.tar.gz
rust-a8b5d4b7f113975e35b1924af608989e0cd620cd.zip
libcore: make result type of iter::from_generator concrete
This allows for propagating trait impls on the iterator type.
-rw-r--r--library/core/src/iter/sources/from_generator.rs22
1 files changed, 18 insertions, 4 deletions
diff --git a/library/core/src/iter/sources/from_generator.rs b/library/core/src/iter/sources/from_generator.rs
index 8e7cbd34a4f..a974d3c892d 100644
--- a/library/core/src/iter/sources/from_generator.rs
+++ b/library/core/src/iter/sources/from_generator.rs
@@ -1,3 +1,4 @@
+use crate::fmt;
 use crate::ops::{Generator, GeneratorState};
 use crate::pin::Pin;
 
@@ -23,14 +24,20 @@ use crate::pin::Pin;
 /// ```
 #[inline]
 #[unstable(feature = "iter_from_generator", issue = "43122", reason = "generators are unstable")]
-pub fn from_generator<G: Generator<Return = ()> + Unpin>(
-    generator: G,
-) -> impl Iterator<Item = G::Yield> {
+pub fn from_generator<G: Generator<Return = ()> + Unpin>(generator: G) -> FromGenerator<G> {
     FromGenerator(generator)
 }
 
-struct FromGenerator<G>(G);
+/// An iterator over the values yielded by an underlying generator.
+///
+/// This `struct` is created by the [`iter::from_generator()`] function. See its documentation for
+/// more.
+///
+/// [`iter::from_generator()`]: from_generator
+#[unstable(feature = "iter_from_generator", issue = "43122", reason = "generators are unstable")]
+pub struct FromGenerator<G>(G);
 
+#[unstable(feature = "iter_from_generator", issue = "43122", reason = "generators are unstable")]
 impl<G: Generator<Return = ()> + Unpin> Iterator for FromGenerator<G> {
     type Item = G::Yield;
 
@@ -41,3 +48,10 @@ impl<G: Generator<Return = ()> + Unpin> Iterator for FromGenerator<G> {
         }
     }
 }
+
+#[unstable(feature = "iter_from_generator", issue = "43122", reason = "generators are unstable")]
+impl<G> fmt::Debug for FromGenerator<G> {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        f.debug_struct("FromGenerator").finish()
+    }
+}