Skip to content

Commit 7e41773

Browse files
author
Clar Fon
committed
Don't expose ChainState to Iterator
1 parent fb974df commit 7e41773

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

src/libcore/iter/adapters/chain.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,14 @@ use super::super::{Iterator, DoubleEndedIterator, FusedIterator, TrustedLen};
1313
#[must_use = "iterators are lazy and do nothing unless consumed"]
1414
#[stable(feature = "rust1", since = "1.0.0")]
1515
pub struct Chain<A, B> {
16-
pub(in super::super) a: A,
17-
pub(in super::super) b: B,
18-
pub(in super::super) state: ChainState,
16+
a: A,
17+
b: B,
18+
state: ChainState,
19+
}
20+
impl<A, B> Chain<A, B> {
21+
pub(in super::super) fn new(a: A, b: B) -> Chain<A, B> {
22+
Chain { a, b, state: ChainState::Both }
23+
}
1924
}
2025

2126
// The iterator protocol specifies that iteration ends with the return value
@@ -32,7 +37,7 @@ pub struct Chain<A, B> {
3237
// The fourth state (neither iterator is remaining) only occurs after Chain has
3338
// returned None once, so we don't need to store this state.
3439
#[derive(Clone, Debug)]
35-
pub(in super::super) enum ChainState {
40+
enum ChainState {
3641
// both front and back iterator are remaining
3742
Both,
3843
// only front is remaining

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

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, ChainState, ZipImpl};
356+
use self::adapters::{flatten_compat, ZipImpl};
357357
pub(crate) use self::adapters::TrustedRandomAccess;
358358

359359
mod range;

src/libcore/iter/traits/iterator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use super::super::{Chain, Cycle, Copied, Cloned, Enumerate, Filter, FilterMap, F
66
use super::super::{Flatten, FlatMap, flatten_compat};
77
use super::super::{Inspect, Map, Peekable, Scan, Skip, SkipWhile, StepBy, Take, TakeWhile, Rev};
88
use super::super::{Zip, Sum, Product};
9-
use super::super::{ChainState, FromIterator, ZipImpl};
9+
use super::super::{FromIterator, ZipImpl};
1010

1111
fn _assert_is_object_safe(_: &dyn Iterator<Item=()>) {}
1212

@@ -425,7 +425,7 @@ pub trait Iterator {
425425
fn chain<U>(self, other: U) -> Chain<Self, U::IntoIter> where
426426
Self: Sized, U: IntoIterator<Item=Self::Item>,
427427
{
428-
Chain{a: self, b: other.into_iter(), state: ChainState::Both}
428+
Chain::new(self, other.into_iter())
429429
}
430430

431431
/// 'Zips up' two iterators into a single iterator of pairs.

0 commit comments

Comments
 (0)