Skip to content

Commit a8b5d4b

Browse files
committed
libcore: make result type of iter::from_generator concrete
This allows for propagating trait impls on the iterator type.
1 parent 0d5573e commit a8b5d4b

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

library/core/src/iter/sources/from_generator.rs

+18-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::fmt;
12
use crate::ops::{Generator, GeneratorState};
23
use crate::pin::Pin;
34

@@ -23,14 +24,20 @@ use crate::pin::Pin;
2324
/// ```
2425
#[inline]
2526
#[unstable(feature = "iter_from_generator", issue = "43122", reason = "generators are unstable")]
26-
pub fn from_generator<G: Generator<Return = ()> + Unpin>(
27-
generator: G,
28-
) -> impl Iterator<Item = G::Yield> {
27+
pub fn from_generator<G: Generator<Return = ()> + Unpin>(generator: G) -> FromGenerator<G> {
2928
FromGenerator(generator)
3029
}
3130

32-
struct FromGenerator<G>(G);
31+
/// An iterator over the values yielded by an underlying generator.
32+
///
33+
/// This `struct` is created by the [`iter::from_generator()`] function. See its documentation for
34+
/// more.
35+
///
36+
/// [`iter::from_generator()`]: from_generator
37+
#[unstable(feature = "iter_from_generator", issue = "43122", reason = "generators are unstable")]
38+
pub struct FromGenerator<G>(G);
3339

40+
#[unstable(feature = "iter_from_generator", issue = "43122", reason = "generators are unstable")]
3441
impl<G: Generator<Return = ()> + Unpin> Iterator for FromGenerator<G> {
3542
type Item = G::Yield;
3643

@@ -41,3 +48,10 @@ impl<G: Generator<Return = ()> + Unpin> Iterator for FromGenerator<G> {
4148
}
4249
}
4350
}
51+
52+
#[unstable(feature = "iter_from_generator", issue = "43122", reason = "generators are unstable")]
53+
impl<G> fmt::Debug for FromGenerator<G> {
54+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
55+
f.debug_struct("FromGenerator").finish()
56+
}
57+
}

0 commit comments

Comments
 (0)