Skip to content

Commit ca92786

Browse files
authored
Merge pull request #1239 from VitalyAnkh/rename_repeatn
rename `repeatn` to `repeat_n`, deprecate `repeatn`, for parity with std
2 parents 7690616 + 452d5af commit ca92786

File tree

6 files changed

+29
-14
lines changed

6 files changed

+29
-14
lines changed

src/iter/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ pub use self::{
190190
panic_fuse::PanicFuse,
191191
par_bridge::{IterBridge, ParallelBridge},
192192
positions::Positions,
193-
repeat::{repeat, repeatn, Repeat, RepeatN},
193+
repeat::{repeat, repeat_n, Repeat, RepeatN},
194194
rev::Rev,
195195
skip::Skip,
196196
skip_any::SkipAny,
@@ -210,6 +210,9 @@ pub use self::{
210210
zip_eq::ZipEq,
211211
};
212212

213+
#[allow(deprecated)]
214+
pub use repeat::repeatn;
215+
213216
/// `IntoParallelIterator` implements the conversion to a [`ParallelIterator`].
214217
///
215218
/// By implementing `IntoParallelIterator` for a type, you define how it will

src/iter/repeat.rs

+17-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub struct Repeat<T: Clone + Send> {
1212
/// cloning it). Note that this iterator has "infinite" length, so
1313
/// typically you would want to use `zip` or `take` or some other
1414
/// means to shorten it, or consider using
15-
/// [the `repeatn()` function](fn.repeatn.html) instead.
15+
/// [the `repeat_n()` function](fn.repeat_n.html) instead.
1616
///
1717
/// # Examples
1818
///
@@ -36,7 +36,7 @@ where
3636
/// The resulting `RepeatN` is an `IndexedParallelIterator`, allowing
3737
/// more functionality than `Repeat` alone.
3838
pub fn take(self, n: usize) -> RepeatN<T> {
39-
repeatn(self.element, n)
39+
repeat_n(self.element, n)
4040
}
4141

4242
/// Iterates tuples, repeating the element with items from another
@@ -97,7 +97,7 @@ impl<T: Clone + Send> UnindexedProducer for RepeatProducer<T> {
9797
}
9898
}
9999

100-
/// Iterator adaptor for [the `repeatn()` function](fn.repeatn.html).
100+
/// Iterator adaptor for [the `repeat_n()` function](fn.repeat_n.html).
101101
#[derive(Debug, Clone)]
102102
pub struct RepeatN<T: Clone + Send> {
103103
element: T,
@@ -111,10 +111,22 @@ pub struct RepeatN<T: Clone + Send> {
111111
///
112112
/// ```
113113
/// use rayon::prelude::*;
114-
/// use rayon::iter::repeatn;
115-
/// let x: Vec<(i32, i32)> = repeatn(22, 3).zip(0..3).collect();
114+
/// use rayon::iter::repeat_n;
115+
/// let x: Vec<(i32, i32)> = repeat_n(22, 3).zip(0..3).collect();
116116
/// assert_eq!(x, vec![(22, 0), (22, 1), (22, 2)]);
117117
/// ```
118+
pub fn repeat_n<T: Clone + Send>(elt: T, n: usize) -> RepeatN<T> {
119+
RepeatN {
120+
element: elt,
121+
count: n,
122+
}
123+
}
124+
125+
/// Creates a parallel iterator that produces `n` repeats of `elt`
126+
/// (by cloning it).
127+
///
128+
/// Deprecated in favor of [`repeat_n`] for consistency with the standard library.
129+
#[deprecated(note = "use `repeat_n`")]
118130
pub fn repeatn<T: Clone + Send>(elt: T, n: usize) -> RepeatN<T> {
119131
RepeatN {
120132
element: elt,

src/iter/test.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2183,19 +2183,19 @@ fn check_repeat_zip() {
21832183
}
21842184

21852185
#[test]
2186-
fn check_repeatn_zip_left() {
2186+
fn check_repeat_n_zip_left() {
21872187
let v = vec![4, 4, 4, 4];
2188-
let mut fours: Vec<_> = repeatn(4, usize::MAX).zip(v).collect();
2188+
let mut fours: Vec<_> = repeat_n(4, usize::MAX).zip(v).collect();
21892189
assert_eq!(fours.len(), 4);
21902190
while let Some(item) = fours.pop() {
21912191
assert_eq!(item, (4, 4));
21922192
}
21932193
}
21942194

21952195
#[test]
2196-
fn check_repeatn_zip_right() {
2196+
fn check_repeat_n_zip_right() {
21972197
let v = vec![4, 4, 4, 4];
2198-
let mut fours: Vec<_> = v.into_par_iter().zip(repeatn(4, usize::MAX)).collect();
2198+
let mut fours: Vec<_> = v.into_par_iter().zip(repeat_n(4, usize::MAX)).collect();
21992199
assert_eq!(fours.len(), 4);
22002200
while let Some(item) = fours.pop() {
22012201
assert_eq!(item, (4, 4));

tests/clones.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ fn clone_once() {
196196
fn clone_repeat() {
197197
let x: Option<i32> = None;
198198
check(rayon::iter::repeat(x).while_some());
199-
check(rayon::iter::repeatn(x, 1000));
199+
check(rayon::iter::repeat_n(x, 1000));
200200
}
201201

202202
#[test]

tests/debug.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ fn debug_once() {
207207
fn debug_repeat() {
208208
let x: Option<i32> = None;
209209
check(rayon::iter::repeat(x));
210-
check(rayon::iter::repeatn(x, 10));
210+
check(rayon::iter::repeat_n(x, 10));
211211
}
212212

213213
#[test]

tests/producer_split_at.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ fn range_inclusive() {
142142
}
143143

144144
#[test]
145-
fn repeatn() {
145+
fn repeat_n() {
146146
let v: Vec<_> = std::iter::repeat(1).take(5).collect();
147-
check(&v, || rayon::iter::repeatn(1, 5));
147+
check(&v, || rayon::iter::repeat_n(1, 5));
148148
}
149149

150150
#[test]

0 commit comments

Comments
 (0)