about summary refs log tree commit diff
diff options
context:
space:
mode:
authorClar Fon <them@lightdark.xyz>2018-12-17 19:31:00 -0500
committerClar Fon <them@lightdark.xyz>2019-01-22 17:45:11 -0500
commit7e4177311adbeb7a1fa64c1f4e1f6610cf96973d (patch)
tree2422092f76d094b301bcfee9570ac9820727c55b
parentfb974df28157f205f81d59ab3fc9cb96d78bf590 (diff)
downloadrust-7e4177311adbeb7a1fa64c1f4e1f6610cf96973d.tar.gz
rust-7e4177311adbeb7a1fa64c1f4e1f6610cf96973d.zip
Don't expose ChainState to Iterator
-rw-r--r--src/libcore/iter/adapters/chain.rs13
-rw-r--r--src/libcore/iter/adapters/mod.rs1
-rw-r--r--src/libcore/iter/mod.rs2
-rw-r--r--src/libcore/iter/traits/iterator.rs4
4 files changed, 12 insertions, 8 deletions
diff --git a/src/libcore/iter/adapters/chain.rs b/src/libcore/iter/adapters/chain.rs
index 5defb857d50..573b096fb46 100644
--- a/src/libcore/iter/adapters/chain.rs
+++ b/src/libcore/iter/adapters/chain.rs
@@ -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
diff --git a/src/libcore/iter/adapters/mod.rs b/src/libcore/iter/adapters/mod.rs
index a3e0696d215..355f86f31ce 100644
--- a/src/libcore/iter/adapters/mod.rs
+++ b/src/libcore/iter/adapters/mod.rs
@@ -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;
diff --git a/src/libcore/iter/mod.rs b/src/libcore/iter/mod.rs
index 1f390d7e0a9..209cf6d9451 100644
--- a/src/libcore/iter/mod.rs
+++ b/src/libcore/iter/mod.rs
@@ -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;
diff --git a/src/libcore/iter/traits/iterator.rs b/src/libcore/iter/traits/iterator.rs
index 0ce817d02a5..bb4549dc903 100644
--- a/src/libcore/iter/traits/iterator.rs
+++ b/src/libcore/iter/traits/iterator.rs
@@ -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.