Skip to content

Commit

Permalink
Don't expose ChainState to Iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
clarfonthey committed Jan 22, 2019
1 parent fb974df commit 7e41773
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
13 changes: 9 additions & 4 deletions src/libcore/iter/adapters/chain.rs
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/libcore/iter/adapters/mod.rs
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/iter/mod.rs
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/iter/traits/iterator.rs
Expand Up @@ -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=()>) {}

Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 7e41773

Please sign in to comment.