Don't expose ChainState to Iterator

This commit is contained in:
Clar Fon 2018-12-17 19:31:00 -05:00
parent fb974df281
commit 7e4177311a
4 changed files with 12 additions and 8 deletions

View file

@ -13,9 +13,14 @@ use super::super::{Iterator, DoubleEndedIterator, FusedIterator, TrustedLen};
#[must_use = "iterators are lazy and do nothing unless consumed"]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Chain<A, B> {
pub(in super::super) a: A,
pub(in super::super) b: B,
pub(in super::super) state: ChainState,
a: A,
b: B,
state: ChainState,
}
impl<A, B> Chain<A, B> {
pub(in super::super) fn new(a: A, b: B) -> Chain<A, B> {
Chain { a, b, state: ChainState::Both }
}
}
// The iterator protocol specifies that iteration ends with the return value
@ -32,7 +37,7 @@ pub struct Chain<A, B> {
// The fourth state (neither iterator is remaining) only occurs after Chain has
// returned None once, so we don't need to store this state.
#[derive(Clone, Debug)]
pub(in super::super) enum ChainState {
enum ChainState {
// both front and back iterator are remaining
Both,
// only front is remaining

View file

@ -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::chain::ChainState;
pub(super) use self::flatten::{FlattenCompat, flatten_compat};
pub(super) use self::zip::ZipImpl;
pub(crate) use self::zip::TrustedRandomAccess;

View file

@ -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, ChainState, ZipImpl};
use self::adapters::{flatten_compat, ZipImpl};
pub(crate) use self::adapters::TrustedRandomAccess;
mod range;

View file

@ -6,7 +6,7 @@ use super::super::{Chain, Cycle, Copied, Cloned, Enumerate, Filter, FilterMap, F
use super::super::{Flatten, FlatMap, flatten_compat};
use super::super::{Inspect, Map, Peekable, Scan, Skip, SkipWhile, StepBy, Take, TakeWhile, Rev};
use super::super::{Zip, Sum, Product};
use super::super::{ChainState, FromIterator, ZipImpl};
use super::super::{FromIterator, ZipImpl};
fn _assert_is_object_safe(_: &dyn Iterator<Item=()>) {}
@ -425,7 +425,7 @@ pub trait Iterator {
fn chain<U>(self, other: U) -> Chain<Self, U::IntoIter> where
Self: Sized, U: IntoIterator<Item=Self::Item>,
{
Chain{a: self, b: other.into_iter(), state: ChainState::Both}
Chain::new(self, other.into_iter())
}
/// 'Zips up' two iterators into a single iterator of pairs.