diff options
| author | Ralf Jung <post@ralfj.de> | 2023-01-15 16:46:17 -0500 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2023-01-15 16:46:17 -0500 |
| commit | b23795229781a2125fade078fa610bc47cc75b16 (patch) | |
| tree | c57813bd1e93312f265ead2df13e5a9f885b17e9 /library/core/src/iter | |
| parent | ec5f8253e28a660034a3936a171f93a3c063a0cc (diff) | |
| parent | fa2ff4d7e5a88bfda186f0f3f621402470745788 (diff) | |
Merge from rustc
Diffstat (limited to 'library/core/src/iter')
| -rw-r--r-- | library/core/src/iter/range.rs | 2 | ||||
| -rw-r--r-- | library/core/src/iter/sources/from_generator.rs | 23 |
2 files changed, 20 insertions, 5 deletions
diff --git a/library/core/src/iter/range.rs b/library/core/src/iter/range.rs index ac7b389b15b..b5739f2f3c0 100644 --- a/library/core/src/iter/range.rs +++ b/library/core/src/iter/range.rs @@ -756,7 +756,7 @@ impl<A: Step> Iterator for ops::Range<A> { where Self: TrustedRandomAccessNoCoerce, { - // SAFETY: The TrustedRandomAccess contract requires that callers only pass an index + // SAFETY: The TrustedRandomAccess contract requires that callers only pass an index // that is in bounds. // Additionally Self: TrustedRandomAccess is only implemented for Copy types // which means even repeated reads of the same index would be safe. diff --git a/library/core/src/iter/sources/from_generator.rs b/library/core/src/iter/sources/from_generator.rs index 8e7cbd34a4f..4cbe731b222 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,21 @@ 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")] +#[derive(Clone)] +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 +49,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() + } +} |
