Skip to content

Commit

Permalink
Merge pull request #318 from bluss/std-deprecations
Browse files Browse the repository at this point in the history
Deprecate methods replaced with versions in std
  • Loading branch information
bluss committed Nov 24, 2018
2 parents 7a5da01 + d2e254f commit 44c9654
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/adaptors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,8 @@ impl<B, F, I> Iterator for Batching<I, F>
/// then skipping forward *n-1* elements.
///
/// See [`.step()`](../trait.Itertools.html#method.step) for more information.
#[deprecated(note="Use std .step_by() instead", since="0.8")]
#[allow(deprecated)]
#[derive(Clone, Debug)]
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
pub struct Step<I> {
Expand All @@ -417,6 +419,7 @@ pub struct Step<I> {
/// Create a `Step` iterator.
///
/// **Panics** if the step is 0.
#[allow(deprecated)]
pub fn step<I>(iter: I, step: usize) -> Step<I>
where I: Iterator
{
Expand All @@ -427,6 +430,7 @@ pub fn step<I>(iter: I, step: usize) -> Step<I>
}
}

#[allow(deprecated)]
impl<I> Iterator for Step<I>
where I: Iterator
{
Expand Down Expand Up @@ -454,6 +458,7 @@ impl<I> Iterator for Step<I>
}

// known size
#[allow(deprecated)]
impl<I> ExactSizeIterator for Step<I>
where I: ExactSizeIterator
{}
Expand Down
14 changes: 11 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ pub mod structs {
Product,
PutBack,
Batching,
Step,
MapResults,
Merge,
MergeBy,
Expand All @@ -72,6 +71,8 @@ pub mod structs {
Positions,
Update,
};
#[allow(deprecated)]
pub use adaptors::Step;
#[cfg(feature = "use_std")]
pub use adaptors::MultiProduct;
#[cfg(feature = "use_std")]
Expand All @@ -94,6 +95,7 @@ pub mod structs {
#[cfg(feature = "use_std")]
pub use rciter_impl::RcIter;
pub use repeatn::RepeatN;
#[allow(deprecated)]
pub use sources::{RepeatCall, Unfold, Iterate};
#[cfg(feature = "use_std")]
pub use tee::Tee;
Expand All @@ -105,6 +107,7 @@ pub mod structs {
pub use zip_longest::ZipLongest;
pub use ziptuple::Zip;
}
#[allow(deprecated)]
pub use structs::*;
pub use concat_impl::concat;
pub use cons_tuples_impl::cons_tuples;
Expand All @@ -116,6 +119,7 @@ pub use minmax::MinMaxResult;
pub use peeking_take_while::PeekingNext;
pub use process_results_impl::process_results;
pub use repeatn::repeat_n;
#[allow(deprecated)]
pub use sources::{repeat_call, unfold, iterate};
pub use with_position::Position;
pub use ziptuple::multizip;
Expand Down Expand Up @@ -628,6 +632,8 @@ pub trait Itertools : Iterator {
/// let it = (0..8).step(3);
/// itertools::assert_equal(it, vec![0, 3, 6]);
/// ```
#[deprecated(note="Use std .step_by() instead", since="0.8")]
#[allow(deprecated)]
fn step(self, n: usize) -> Step<Self>
where Self: Sized
{
Expand Down Expand Up @@ -1332,11 +1338,12 @@ pub trait Itertools : Iterator {
///
/// itertools::assert_equal(rx.iter(), vec![1, 3, 5, 7, 9]);
/// ```
fn foreach<F>(self, mut f: F)
#[deprecated(note="Use .for_each() instead", since="0.8")]
fn foreach<F>(self, f: F)
where F: FnMut(Self::Item),
Self: Sized,
{
self.fold((), move |(), element| f(element))
self.for_each(f)
}

/// Combine all an iterator's elements into one element by using `Extend`.
Expand Down Expand Up @@ -1742,6 +1749,7 @@ pub trait Itertools : Iterator {
/// The big difference between the computations of `result2` and `result3` is that while
/// `fold()` called the provided closure for every item of the callee iterator,
/// `fold_while()` actually stopped iterating as soon as it encountered `Fold::Done(_)`.
#[deprecated(note="Use .try_fold() instead", since="0.8")]
fn fold_while<B, F>(&mut self, init: B, mut f: F) -> FoldWhile<B>
where Self: Sized,
F: FnMut(B, Self::Item) -> FoldWhile<B>
Expand Down
3 changes: 3 additions & 0 deletions src/sources.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
//! Iterators that are sources (produce elements from parameters,
//! not from another iterator).
#![allow(deprecated)]

use std::fmt;
use std::mem;

/// See [`repeat_call`](../fn.repeat_call.html) for more information.
#[deprecated(note="Use std repeat_with() instead", since="0.8")]
pub struct RepeatCall<F> {
f: F,
}
Expand Down Expand Up @@ -36,6 +38,7 @@ impl<F> fmt::Debug for RepeatCall<F>
/// vec![1, 1, 1, 1, 1]
/// );
/// ```
#[deprecated(note="Use std repeat_with() instead", since="0.8")]
pub fn repeat_call<F, A>(function: F) -> RepeatCall<F>
where F: FnMut() -> A
{
Expand Down
6 changes: 6 additions & 0 deletions tests/quick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ quickcheck! {
assert_eq!(answer.into_iter().last(), a.clone().multi_cartesian_product().last());
}

#[allow(deprecated)]
fn size_step(a: Iter<i16, Exact>, s: usize) -> bool {
let mut s = s;
if s == 0 {
Expand All @@ -414,6 +415,8 @@ quickcheck! {
correct_size_hint(filt.step(s)) &&
exact_size(a.step(s))
}

#[allow(deprecated)]
fn equal_step(a: Iter<i16>, s: usize) -> bool {
let mut s = s;
if s == 0 {
Expand All @@ -426,6 +429,8 @@ quickcheck! {
keep
}))
}

#[allow(deprecated)]
fn equal_step_vec(a: Vec<i16>, s: usize) -> bool {
let mut s = s;
if s == 0 {
Expand Down Expand Up @@ -980,6 +985,7 @@ quickcheck! {
}

quickcheck! {
#[allow(deprecated)]
fn tree_fold1_f64(mut a: Vec<f64>) -> TestResult {
fn collapse_adjacent<F>(x: Vec<f64>, mut f: F) -> Vec<f64>
where F: FnMut(f64, f64) -> f64
Expand Down
3 changes: 3 additions & 0 deletions tests/test_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ fn test_interleave() {
it::assert_equal(it, rs.iter());
}

#[allow(deprecated)]
#[test]
fn foreach() {
let xs = [1i32, 2, 3];
Expand Down Expand Up @@ -159,13 +160,15 @@ fn test_put_back() {
it::assert_equal(pb, xs.iter().cloned());
}

#[allow(deprecated)]
#[test]
fn step() {
it::assert_equal((0..10).step(1), 0..10);
it::assert_equal((0..10).step(2), (0..10).filter(|x: &i32| *x % 2 == 0));
it::assert_equal((0..10).step(10), 0..1);
}

#[allow(deprecated)]
#[test]
fn merge() {
it::assert_equal((0..10).step(2).merge((1..10).step(2)), 0..10);
Expand Down
4 changes: 4 additions & 0 deletions tests/test_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ fn test_rciter() {
assert_eq!(z.next(), Some((0, 1)));
}

#[allow(deprecated)]
#[test]
fn trait_pointers() {
struct ByRef<'r, I: ?Sized>(&'r mut I) where I: 'r;
Expand Down Expand Up @@ -220,13 +221,15 @@ fn merge_by_btree() {
it::assert_equal(results, expected.into_iter());
}

#[allow(deprecated)]
#[test]
fn kmerge() {
let its = (0..4).map(|s| (s..10).step(4));

it::assert_equal(its.kmerge(), 0..10);
}

#[allow(deprecated)]
#[test]
fn kmerge_2() {
let its = vec![3, 2, 1, 0].into_iter().map(|s| (s..10).step(4));
Expand Down Expand Up @@ -684,6 +687,7 @@ fn while_some() {
it::assert_equal(ns, vec![1, 2, 3, 4]);
}

#[allow(deprecated)]
#[test]
fn fold_while() {
let mut iterations = 0;
Expand Down

0 comments on commit 44c9654

Please sign in to comment.