Don't expose FlattenCompat to Iterator
This commit is contained in:
parent
7e4177311a
commit
53b400c30c
4 changed files with 24 additions and 13 deletions
|
|
@ -14,7 +14,12 @@ use super::Map;
|
|||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub struct FlatMap<I, U: IntoIterator, F> {
|
||||
pub(in super::super) inner: FlattenCompat<Map<I, F>, <U as IntoIterator>::IntoIter>
|
||||
inner: FlattenCompat<Map<I, F>, <U as IntoIterator>::IntoIter>
|
||||
}
|
||||
impl<I: Iterator, U: IntoIterator, F: FnMut(I::Item) -> U> FlatMap<I, U, F> {
|
||||
pub(in super::super) fn new(iter: I, f: F) -> FlatMap<I, U, F> {
|
||||
FlatMap { inner: FlattenCompat::new(iter.map(f)) }
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
|
|
@ -100,7 +105,13 @@ impl<I, U, F> FusedIterator for FlatMap<I, U, F>
|
|||
#[stable(feature = "iterator_flatten", since = "1.29.0")]
|
||||
pub struct Flatten<I: Iterator>
|
||||
where I::Item: IntoIterator {
|
||||
pub(in super::super) inner: FlattenCompat<I, <I::Item as IntoIterator>::IntoIter>,
|
||||
inner: FlattenCompat<I, <I::Item as IntoIterator>::IntoIter>,
|
||||
}
|
||||
impl<I: Iterator> Flatten<I>
|
||||
where I::Item: IntoIterator {
|
||||
pub(in super::super) fn new(iter: I) -> Flatten<I> {
|
||||
Flatten { inner: FlattenCompat::new(iter) }
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "iterator_flatten", since = "1.29.0")]
|
||||
|
|
@ -177,19 +188,20 @@ impl<I, U> FusedIterator for Flatten<I>
|
|||
where I: FusedIterator, U: Iterator,
|
||||
I::Item: IntoIterator<IntoIter = U, Item = U::Item> {}
|
||||
|
||||
/// Adapts an iterator by flattening it, for use in `flatten()` and `flat_map()`.
|
||||
pub(in super::super) fn flatten_compat<I, U>(iter: I) -> FlattenCompat<I, U> {
|
||||
FlattenCompat { iter, frontiter: None, backiter: None }
|
||||
}
|
||||
|
||||
/// Real logic of both `Flatten` and `FlatMap` which simply delegate to
|
||||
/// this type.
|
||||
#[derive(Clone, Debug)]
|
||||
pub(in super::super) struct FlattenCompat<I, U> {
|
||||
struct FlattenCompat<I, U> {
|
||||
iter: I,
|
||||
frontiter: Option<U>,
|
||||
backiter: Option<U>,
|
||||
}
|
||||
impl<I, U> FlattenCompat<I, U> {
|
||||
/// Adapts an iterator by flattening it, for use in `flatten()` and `flat_map()`.
|
||||
fn new(iter: I) -> FlattenCompat<I, U> {
|
||||
FlattenCompat { iter, frontiter: None, backiter: None }
|
||||
}
|
||||
}
|
||||
|
||||
impl<I, U> Iterator for FlattenCompat<I, U>
|
||||
where I: Iterator, U: Iterator,
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ mod zip;
|
|||
pub use self::chain::Chain;
|
||||
pub use self::flatten::{FlatMap, Flatten};
|
||||
pub use self::zip::Zip;
|
||||
pub(super) use self::flatten::{FlattenCompat, flatten_compat};
|
||||
pub(super) use self::zip::ZipImpl;
|
||||
pub(crate) use self::zip::TrustedRandomAccess;
|
||||
|
||||
|
|
|
|||
|
|
@ -353,7 +353,7 @@ pub use self::adapters::Flatten;
|
|||
#[unstable(feature = "iter_copied", issue = "57127")]
|
||||
pub use self::adapters::Copied;
|
||||
|
||||
use self::adapters::{flatten_compat, ZipImpl};
|
||||
use self::adapters::ZipImpl;
|
||||
pub(crate) use self::adapters::TrustedRandomAccess;
|
||||
|
||||
mod range;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use ops::Try;
|
|||
|
||||
use super::super::LoopState;
|
||||
use super::super::{Chain, Cycle, Copied, Cloned, Enumerate, Filter, FilterMap, Fuse};
|
||||
use super::super::{Flatten, FlatMap, flatten_compat};
|
||||
use super::super::{Flatten, FlatMap};
|
||||
use super::super::{Inspect, Map, Peekable, Scan, Skip, SkipWhile, StepBy, Take, TakeWhile, Rev};
|
||||
use super::super::{Zip, Sum, Product};
|
||||
use super::super::{FromIterator, ZipImpl};
|
||||
|
|
@ -1098,7 +1098,7 @@ pub trait Iterator {
|
|||
fn flat_map<U, F>(self, f: F) -> FlatMap<Self, U, F>
|
||||
where Self: Sized, U: IntoIterator, F: FnMut(Self::Item) -> U,
|
||||
{
|
||||
FlatMap { inner: flatten_compat(self.map(f)) }
|
||||
FlatMap::new(self, f)
|
||||
}
|
||||
|
||||
/// Creates an iterator that flattens nested structure.
|
||||
|
|
@ -1166,7 +1166,7 @@ pub trait Iterator {
|
|||
#[stable(feature = "iterator_flatten", since = "1.29.0")]
|
||||
fn flatten(self) -> Flatten<Self>
|
||||
where Self: Sized, Self::Item: IntoIterator {
|
||||
Flatten { inner: flatten_compat(self) }
|
||||
Flatten::new(self)
|
||||
}
|
||||
|
||||
/// Creates an iterator which ends after the first [`None`].
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue