Skip to content

Commit 085d2f1

Browse files
authored
Rollup merge of #105526 - Xiretza:iter-from-generator-derive, r=scottmcm
libcore: make result of iter::from_generator Clone `@rustbot` label +A-generators
2 parents 4b51adf + 17a0740 commit 085d2f1

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

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

+19-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,21 @@ 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+
#[derive(Clone)]
39+
pub struct FromGenerator<G>(G);
3340

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

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

0 commit comments

Comments
 (0)