Skip to content

Commit 8195ffe

Browse files
committed
Merge pull request #13 from aepsil0n/new-for-loop
Adapt code to the new semantics of the for-loop
2 parents 4e3c3bd + e304f87 commit 8195ffe

File tree

4 files changed

+23
-23
lines changed

4 files changed

+23
-23
lines changed

src/adaptors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ impl<I: Iterator> Iterator for Dedup<I> where
287287
#[inline]
288288
fn next(&mut self) -> Option<I::Item>
289289
{
290-
for elt in self.iter {
290+
for elt in self.iter.by_ref() {
291291
match self.last {
292292
Some(ref x) if x == &elt => continue,
293293
None => {
@@ -391,7 +391,7 @@ impl<K: PartialEq, I: Iterator, F: FnMut(&I::Item) -> K>
391391
type Item = (K, Vec<I::Item>);
392392
fn next(&mut self) -> Option<(K, Vec<I::Item>)>
393393
{
394-
for elt in self.iter {
394+
for elt in self.iter.by_ref() {
395395
let key = (self.key)(&elt);
396396
match self.current_key.take() {
397397
None => {}

src/lib.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -428,9 +428,10 @@ pub trait Itertools : Iterator {
428428
/// Find the position and value of the first element satisfying a predicate.
429429
fn find_position<P>(&mut self, mut pred: P) -> Option<(usize, Self::Item)> where
430430
P: FnMut(&Self::Item) -> bool,
431+
Self: Sized,
431432
{
432433
let mut index = 0us;
433-
for elt in *self {
434+
for elt in IteratorExt::by_ref(self) {
434435
if pred(&elt) {
435436
return Some((index, elt))
436437
}
@@ -477,27 +478,30 @@ pub trait Itertools : Iterator {
477478
/// "hi".chars().map(|c| cnt += 1).drain();
478479
/// ```
479480
///
480-
fn drain(&mut self)
481+
fn drain(&mut self) where
482+
Self: Sized
481483
{
482-
for _ in *self { /* nothing */ }
484+
for _ in self.by_ref() { /* nothing */ }
483485
}
484486

485487
/// Run the closure **f** eagerly on each element of the iterator.
486488
///
487489
/// Consumes the iterator until its end.
488490
///
489491
/// **Note: This method is deprecated, use .foreach() instead.**
490-
fn apply<F: FnMut(Self::Item)>(&mut self, f: F)
492+
fn apply<F: FnMut(Self::Item)>(&mut self, f: F) where
493+
Self: Sized
491494
{
492495
self.foreach(f)
493496
}
494497

495498
/// Run the closure **f** eagerly on each element of the iterator.
496499
///
497500
/// Consumes the iterator until its end.
498-
fn foreach<F: FnMut(Self::Item)>(&mut self, mut f: F)
501+
fn foreach<F: FnMut(Self::Item)>(&mut self, mut f: F) where
502+
Self: Sized
499503
{
500-
for elt in *self { f(elt) }
504+
for elt in self.by_ref() { f(elt) }
501505
}
502506

503507
/// **.collec_vec()** is simply a type specialization of **.collect()**,
@@ -517,7 +521,7 @@ impl<T: ?Sized> Itertools for T where T: Iterator { }
517521
/// Return the number of elements written.
518522
#[inline]
519523
pub fn write<'a, A: 'a, I: Iterator<Item=&'a mut A>, J: Iterator<Item=A>>
520-
(mut to: I, mut from: J) -> usize
524+
(mut to: I, from: J) -> usize
521525
{
522526
let mut count = 0;
523527
for elt in from {

tests/tests.rs

+8-11
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//! option. This file may not be copied, modified, or distributed
55
//! except according to those terms.
66
7-
#![feature(core, collections, test)]
7+
#![feature(core, test)]
88

99
#[macro_use]
1010
extern crate itertools;
@@ -276,20 +276,17 @@ fn rciter() {
276276

277277
#[test]
278278
fn slice() {
279-
280-
let it = 0..10;
281-
assert_iters_equal(it.slice(..3), 0..3);
282-
assert_iters_equal(it.slice(3..7), 3..7);
283-
assert_iters_equal(it.slice(3..27), 3..10);
284-
assert_iters_equal(it.slice(44..), 0..0);
279+
assert_iters_equal((0..10).slice(..3), 0..3);
280+
assert_iters_equal((0..10).slice(3..7), 3..7);
281+
assert_iters_equal((0..10).slice(3..27), 3..10);
282+
assert_iters_equal((0..10).slice(44..), 0..0);
285283
}
286284

287285
#[test]
288286
fn step() {
289-
let it = 0..10;
290-
assert_iters_equal(it.step(1), it);
291-
assert_iters_equal(it.step(2), it.filter(|x: &i32| *x % 2 == 0));
292-
assert_iters_equal(it.step(10), 0..1);
287+
assert_iters_equal((0..10).step(1), (0..10));
288+
assert_iters_equal((0..10).step(2), (0..10).filter(|x: &i32| *x % 2 == 0));
289+
assert_iters_equal((0..10).step(10), 0..1);
293290
}
294291

295292
#[test]

tests/zip.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@ fn test_zip_longest_size_hint() {
1515
let c = count(0, 1);
1616
let v: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
1717
let v2 = &[10, 11, 12];
18-
let vi = v.iter();
1918

20-
assert_eq!(c.zip_longest(vi).size_hint(), (std::usize::MAX, None));
19+
assert_eq!(c.zip_longest(v.iter()).size_hint(), (std::usize::MAX, None));
2120

22-
assert_eq!(vi.zip_longest(v2.iter()).size_hint(), (10, Some(10)));
21+
assert_eq!(v.iter().zip_longest(v2.iter()).size_hint(), (10, Some(10)));
2322
}
2423
#[test]
2524
fn test_double_ended_zip_longest() {

0 commit comments

Comments
 (0)