Skip to content

Commit 53b400c

Browse files
author
Clar Fon
committed
Don't expose FlattenCompat to Iterator
1 parent 7e41773 commit 53b400c

File tree

4 files changed

+24
-13
lines changed

4 files changed

+24
-13
lines changed

src/libcore/iter/adapters/flatten.rs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ use super::Map;
1414
#[must_use = "iterators are lazy and do nothing unless consumed"]
1515
#[stable(feature = "rust1", since = "1.0.0")]
1616
pub struct FlatMap<I, U: IntoIterator, F> {
17-
pub(in super::super) inner: FlattenCompat<Map<I, F>, <U as IntoIterator>::IntoIter>
17+
inner: FlattenCompat<Map<I, F>, <U as IntoIterator>::IntoIter>
18+
}
19+
impl<I: Iterator, U: IntoIterator, F: FnMut(I::Item) -> U> FlatMap<I, U, F> {
20+
pub(in super::super) fn new(iter: I, f: F) -> FlatMap<I, U, F> {
21+
FlatMap { inner: FlattenCompat::new(iter.map(f)) }
22+
}
1823
}
1924

2025
#[stable(feature = "rust1", since = "1.0.0")]
@@ -100,7 +105,13 @@ impl<I, U, F> FusedIterator for FlatMap<I, U, F>
100105
#[stable(feature = "iterator_flatten", since = "1.29.0")]
101106
pub struct Flatten<I: Iterator>
102107
where I::Item: IntoIterator {
103-
pub(in super::super) inner: FlattenCompat<I, <I::Item as IntoIterator>::IntoIter>,
108+
inner: FlattenCompat<I, <I::Item as IntoIterator>::IntoIter>,
109+
}
110+
impl<I: Iterator> Flatten<I>
111+
where I::Item: IntoIterator {
112+
pub(in super::super) fn new(iter: I) -> Flatten<I> {
113+
Flatten { inner: FlattenCompat::new(iter) }
114+
}
104115
}
105116

106117
#[stable(feature = "iterator_flatten", since = "1.29.0")]
@@ -177,19 +188,20 @@ impl<I, U> FusedIterator for Flatten<I>
177188
where I: FusedIterator, U: Iterator,
178189
I::Item: IntoIterator<IntoIter = U, Item = U::Item> {}
179190

180-
/// Adapts an iterator by flattening it, for use in `flatten()` and `flat_map()`.
181-
pub(in super::super) fn flatten_compat<I, U>(iter: I) -> FlattenCompat<I, U> {
182-
FlattenCompat { iter, frontiter: None, backiter: None }
183-
}
184-
185191
/// Real logic of both `Flatten` and `FlatMap` which simply delegate to
186192
/// this type.
187193
#[derive(Clone, Debug)]
188-
pub(in super::super) struct FlattenCompat<I, U> {
194+
struct FlattenCompat<I, U> {
189195
iter: I,
190196
frontiter: Option<U>,
191197
backiter: Option<U>,
192198
}
199+
impl<I, U> FlattenCompat<I, U> {
200+
/// Adapts an iterator by flattening it, for use in `flatten()` and `flat_map()`.
201+
fn new(iter: I) -> FlattenCompat<I, U> {
202+
FlattenCompat { iter, frontiter: None, backiter: None }
203+
}
204+
}
193205

194206
impl<I, U> Iterator for FlattenCompat<I, U>
195207
where I: Iterator, U: Iterator,

src/libcore/iter/adapters/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ mod zip;
1313
pub use self::chain::Chain;
1414
pub use self::flatten::{FlatMap, Flatten};
1515
pub use self::zip::Zip;
16-
pub(super) use self::flatten::{FlattenCompat, flatten_compat};
1716
pub(super) use self::zip::ZipImpl;
1817
pub(crate) use self::zip::TrustedRandomAccess;
1918

src/libcore/iter/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ pub use self::adapters::Flatten;
353353
#[unstable(feature = "iter_copied", issue = "57127")]
354354
pub use self::adapters::Copied;
355355

356-
use self::adapters::{flatten_compat, ZipImpl};
356+
use self::adapters::ZipImpl;
357357
pub(crate) use self::adapters::TrustedRandomAccess;
358358

359359
mod range;

src/libcore/iter/traits/iterator.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use ops::Try;
33

44
use super::super::LoopState;
55
use super::super::{Chain, Cycle, Copied, Cloned, Enumerate, Filter, FilterMap, Fuse};
6-
use super::super::{Flatten, FlatMap, flatten_compat};
6+
use super::super::{Flatten, FlatMap};
77
use super::super::{Inspect, Map, Peekable, Scan, Skip, SkipWhile, StepBy, Take, TakeWhile, Rev};
88
use super::super::{Zip, Sum, Product};
99
use super::super::{FromIterator, ZipImpl};
@@ -1098,7 +1098,7 @@ pub trait Iterator {
10981098
fn flat_map<U, F>(self, f: F) -> FlatMap<Self, U, F>
10991099
where Self: Sized, U: IntoIterator, F: FnMut(Self::Item) -> U,
11001100
{
1101-
FlatMap { inner: flatten_compat(self.map(f)) }
1101+
FlatMap::new(self, f)
11021102
}
11031103

11041104
/// Creates an iterator that flattens nested structure.
@@ -1166,7 +1166,7 @@ pub trait Iterator {
11661166
#[stable(feature = "iterator_flatten", since = "1.29.0")]
11671167
fn flatten(self) -> Flatten<Self>
11681168
where Self: Sized, Self::Item: IntoIterator {
1169-
Flatten { inner: flatten_compat(self) }
1169+
Flatten::new(self)
11701170
}
11711171

11721172
/// Creates an iterator which ends after the first [`None`].

0 commit comments

Comments
 (0)