about summary refs log tree commit diff
path: root/src/libcore/iter
diff options
context:
space:
mode:
authorClar Fon <them@lightdark.xyz>2018-12-17 21:39:07 -0500
committerClar Fon <them@lightdark.xyz>2019-01-22 17:45:11 -0500
commit02bda7a0617fd0d0d3ac11dffb17ffba8c0f0601 (patch)
treeb629c5c2d3dcc5b1fbf71cdf7b62ac6521831b11 /src/libcore/iter
parent4c28b2c4b171be143d2a5ca7c0c389e9d3d7f26a (diff)
downloadrust-02bda7a0617fd0d0d3ac11dffb17ffba8c0f0601.tar.gz
rust-02bda7a0617fd0d0d3ac11dffb17ffba8c0f0601.zip
Move trivial constructors to inherent methods
Diffstat (limited to 'src/libcore/iter')
-rw-r--r--src/libcore/iter/adapters/mod.rs82
-rw-r--r--src/libcore/iter/traits/iterator.rs20
2 files changed, 76 insertions, 26 deletions
diff --git a/src/libcore/iter/adapters/mod.rs b/src/libcore/iter/adapters/mod.rs
index 8bd064021e6..f8d6bedeace 100644
--- a/src/libcore/iter/adapters/mod.rs
+++ b/src/libcore/iter/adapters/mod.rs
@@ -26,7 +26,12 @@ pub(crate) use self::zip::TrustedRandomAccess;
 #[must_use = "iterators are lazy and do nothing unless consumed"]
 #[stable(feature = "rust1", since = "1.0.0")]
 pub struct Rev<T> {
-    pub(super) iter: T
+    iter: T
+}
+impl<T> Rev<T> {
+    pub(super) fn new(iter: T) -> Rev<T> {
+        Rev { iter }
+    }
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
@@ -127,7 +132,12 @@ unsafe impl<I> TrustedLen for Rev<I>
 #[must_use = "iterators are lazy and do nothing unless consumed"]
 #[derive(Clone, Debug)]
 pub struct Copied<I> {
-    pub(super) it: I,
+    it: I,
+}
+impl<I> Copied<I> {
+    pub(super) fn new(it: I) -> Copied<I> {
+        Copied { it }
+    }
 }
 
 #[unstable(feature = "iter_copied", issue = "57127")]
@@ -227,7 +237,12 @@ unsafe impl<'a, I, T: 'a> TrustedLen for Copied<I>
 #[must_use = "iterators are lazy and do nothing unless consumed"]
 #[derive(Clone, Debug)]
 pub struct Cloned<I> {
-    pub(super) it: I,
+    it: I,
+}
+impl<I> Cloned<I> {
+    pub(super) fn new(it: I) -> Cloned<I> {
+        Cloned { it }
+    }
 }
 
 #[stable(feature = "iter_cloned", since = "1.1.0")]
@@ -525,8 +540,13 @@ impl<I> ExactSizeIterator for StepBy<I> where I: ExactSizeIterator {}
 #[stable(feature = "rust1", since = "1.0.0")]
 #[derive(Clone)]
 pub struct Map<I, F> {
-    pub(super) iter: I,
-    pub(super) f: F,
+    iter: I,
+    f: F,
+}
+impl<I, F> Map<I, F> {
+    pub(super) fn new(iter: I, f: F) -> Map<I, F> {
+        Map { iter, f }
+    }
 }
 
 #[stable(feature = "core_impl_debug", since = "1.9.0")]
@@ -636,8 +656,13 @@ unsafe impl<B, I, F> TrustedRandomAccess for Map<I, F>
 #[stable(feature = "rust1", since = "1.0.0")]
 #[derive(Clone)]
 pub struct Filter<I, P> {
-    pub(super) iter: I,
-    pub(super) predicate: P,
+    iter: I,
+    predicate: P,
+}
+impl<I, P> Filter<I, P> {
+    pub(super) fn new(iter: I, predicate: P) -> Filter<I, P> {
+        Filter { iter, predicate }
+    }
 }
 
 #[stable(feature = "core_impl_debug", since = "1.9.0")]
@@ -768,8 +793,13 @@ impl<I: FusedIterator, P> FusedIterator for Filter<I, P>
 #[stable(feature = "rust1", since = "1.0.0")]
 #[derive(Clone)]
 pub struct FilterMap<I, F> {
-    pub(super) iter: I,
-    pub(super) f: F,
+    iter: I,
+    f: F,
+}
+impl<I, F> FilterMap<I, F> {
+    pub(super) fn new(iter: I, f: F) -> FilterMap<I, F> {
+        FilterMap { iter, f }
+    }
 }
 
 #[stable(feature = "core_impl_debug", since = "1.9.0")]
@@ -1377,8 +1407,13 @@ impl<I, P> FusedIterator for TakeWhile<I, P>
 #[must_use = "iterators are lazy and do nothing unless consumed"]
 #[stable(feature = "rust1", since = "1.0.0")]
 pub struct Skip<I> {
-    pub(super) iter: I,
-    pub(super) n: usize
+    iter: I,
+    n: usize
+}
+impl<I> Skip<I> {
+    pub(super) fn new(iter: I, n: usize) -> Skip<I> {
+        Skip { iter, n }
+    }
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
@@ -1518,6 +1553,11 @@ pub struct Take<I> {
     pub(super) iter: I,
     pub(super) n: usize
 }
+impl<I> Take<I> {
+    pub(super) fn new(iter: I, n: usize) -> Take<I> {
+        Take { iter, n }
+    }
+}
 
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<I> Iterator for Take<I> where I: Iterator{
@@ -1603,9 +1643,14 @@ unsafe impl<I: TrustedLen> TrustedLen for Take<I> {}
 #[stable(feature = "rust1", since = "1.0.0")]
 #[derive(Clone)]
 pub struct Scan<I, St, F> {
-    pub(super) iter: I,
-    pub(super) f: F,
-    pub(super) state: St,
+    iter: I,
+    f: F,
+    state: St,
+}
+impl<I, St, F> Scan<I, St, F> {
+    pub(super) fn new(iter: I, state: St, f: F) -> Scan<I, St, F> {
+        Scan { iter, state, f }
+    }
 }
 
 #[stable(feature = "core_impl_debug", since = "1.9.0")]
@@ -1893,8 +1938,13 @@ impl<I> ExactSizeIterator for Fuse<I> where I: ExactSizeIterator {
 #[stable(feature = "rust1", since = "1.0.0")]
 #[derive(Clone)]
 pub struct Inspect<I, F> {
-    pub(super) iter: I,
-    pub(super) f: F,
+    iter: I,
+    f: F,
+}
+impl<I, F> Inspect<I, F> {
+    pub(super) fn new(iter: I, f: F) -> Inspect<I, F> {
+        Inspect { iter, f }
+    }
 }
 
 #[stable(feature = "core_impl_debug", since = "1.9.0")]
diff --git a/src/libcore/iter/traits/iterator.rs b/src/libcore/iter/traits/iterator.rs
index 44e29fd813a..9dfa83f473b 100644
--- a/src/libcore/iter/traits/iterator.rs
+++ b/src/libcore/iter/traits/iterator.rs
@@ -558,7 +558,7 @@ pub trait Iterator {
     fn map<B, F>(self, f: F) -> Map<Self, F> where
         Self: Sized, F: FnMut(Self::Item) -> B,
     {
-        Map { iter: self, f }
+        Map::new(self, f)
     }
 
     /// Calls a closure on each element of an iterator.
@@ -669,7 +669,7 @@ pub trait Iterator {
     fn filter<P>(self, predicate: P) -> Filter<Self, P> where
         Self: Sized, P: FnMut(&Self::Item) -> bool,
     {
-        Filter {iter: self, predicate }
+        Filter::new(self, predicate)
     }
 
     /// Creates an iterator that both filters and maps.
@@ -726,7 +726,7 @@ pub trait Iterator {
     fn filter_map<B, F>(self, f: F) -> FilterMap<Self, F> where
         Self: Sized, F: FnMut(Self::Item) -> Option<B>,
     {
-        FilterMap { iter: self, f }
+        FilterMap::new(self, f)
     }
 
     /// Creates an iterator which gives the current iteration count as well as
@@ -981,7 +981,7 @@ pub trait Iterator {
     #[inline]
     #[stable(feature = "rust1", since = "1.0.0")]
     fn skip(self, n: usize) -> Skip<Self> where Self: Sized {
-        Skip { iter: self, n }
+        Skip::new(self, n)
     }
 
     /// Creates an iterator that yields its first `n` elements.
@@ -1013,7 +1013,7 @@ pub trait Iterator {
     #[inline]
     #[stable(feature = "rust1", since = "1.0.0")]
     fn take(self, n: usize) -> Take<Self> where Self: Sized, {
-        Take { iter: self, n }
+        Take::new(self, n)
     }
 
     /// An iterator adaptor similar to [`fold`] that holds internal state and
@@ -1058,7 +1058,7 @@ pub trait Iterator {
     fn scan<St, B, F>(self, initial_state: St, f: F) -> Scan<Self, St, F>
         where Self: Sized, F: FnMut(&mut St, Self::Item) -> Option<B>,
     {
-        Scan { iter: self, f, state: initial_state }
+        Scan::new(self, initial_state, f)
     }
 
     /// Creates an iterator that works like map, but flattens nested structure.
@@ -1307,7 +1307,7 @@ pub trait Iterator {
     fn inspect<F>(self, f: F) -> Inspect<Self, F> where
         Self: Sized, F: FnMut(&Self::Item),
     {
-        Inspect { iter: self, f }
+        Inspect::new(self, f)
     }
 
     /// Borrows an iterator, rather than consuming it.
@@ -2181,7 +2181,7 @@ pub trait Iterator {
     #[inline]
     #[stable(feature = "rust1", since = "1.0.0")]
     fn rev(self) -> Rev<Self> where Self: Sized + DoubleEndedIterator {
-        Rev{iter: self}
+        Rev::new(self)
     }
 
     /// Converts an iterator of pairs into a pair of containers.
@@ -2249,7 +2249,7 @@ pub trait Iterator {
     fn copied<'a, T: 'a>(self) -> Copied<Self>
         where Self: Sized + Iterator<Item=&'a T>, T: Copy
     {
-        Copied { it: self }
+        Copied::new(self)
     }
 
     /// Creates an iterator which [`clone`]s all of its elements.
@@ -2278,7 +2278,7 @@ pub trait Iterator {
     fn cloned<'a, T: 'a>(self) -> Cloned<Self>
         where Self: Sized + Iterator<Item=&'a T>, T: Clone
     {
-        Cloned { it: self }
+        Cloned::new(self)
     }
 
     /// Repeats an iterator endlessly.