diff --git a/src/adaptors/map.rs b/src/adaptors/map.rs index ce7c762cb..ff377f700 100644 --- a/src/adaptors/map.rs +++ b/src/adaptors/map.rs @@ -68,7 +68,7 @@ where pub type MapOk = MapSpecialCase>; /// See [`MapOk`](struct.MapOk.html). -#[deprecated(note = "Use MapOk instead", since = "0.10")] +#[deprecated(note = "Use MapOk instead", since = "0.10.0")] pub type MapResults = MapOk; impl MapSpecialCaseFn> for MapSpecialCaseFnOk diff --git a/src/adaptors/mod.rs b/src/adaptors/mod.rs index d98f6fe7c..0b9d1185f 100644 --- a/src/adaptors/mod.rs +++ b/src/adaptors/mod.rs @@ -113,22 +113,11 @@ impl Iterator for InterleaveShortest #[inline] fn next(&mut self) -> Option { - match self.phase { - false => match self.it0.next() { - None => None, - e => { - self.phase = true; - e - } - }, - true => match self.it1.next() { - None => None, - e => { - self.phase = false; - e - } - }, + let e = if self.phase { self.it1.next() } else { self.it0.next() }; + if e.is_some() { + self.phase = !self.phase; } + e } #[inline] @@ -412,7 +401,7 @@ impl Iterator for Batching /// 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")] +#[deprecated(note="Use std .step_by() instead", since="0.8.0")] #[allow(deprecated)] #[derive(Clone, Debug)] #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] diff --git a/src/adaptors/multi_product.rs b/src/adaptors/multi_product.rs index 4a31713ab..532333a48 100644 --- a/src/adaptors/multi_product.rs +++ b/src/adaptors/multi_product.rs @@ -161,7 +161,7 @@ impl Iterator for MultiProduct } fn count(self) -> usize { - if self.0.len() == 0 { + if self.0.is_empty() { return 0; } @@ -183,7 +183,7 @@ impl Iterator for MultiProduct fn size_hint(&self) -> (usize, Option) { // Not ExactSizeIterator because size may be larger than usize - if self.0.len() == 0 { + if self.0.is_empty() { return (0, Some(0)); } diff --git a/src/combinations.rs b/src/combinations.rs index 875951808..a8b612f17 100644 --- a/src/combinations.rs +++ b/src/combinations.rs @@ -56,7 +56,7 @@ impl Iterator for Combinations return None; } self.first = false; - } else if self.indices.len() == 0 { + } else if self.indices.is_empty() { return None; } else { // Scan from the end, looking for an index to increment diff --git a/src/concat_impl.rs b/src/concat_impl.rs index 6048d18f6..0233d01f6 100644 --- a/src/concat_impl.rs +++ b/src/concat_impl.rs @@ -18,5 +18,5 @@ pub fn concat(iterable: I) -> I::Item where I: IntoIterator, I::Item: Extend<<::Item as IntoIterator>::Item> + IntoIterator + Default { - iterable.into_iter().fold1(|mut a, b| { a.extend(b); a }).unwrap_or_else(|| <_>::default()) + iterable.into_iter().fold1(|mut a, b| { a.extend(b); a }).unwrap_or_else(<_>::default) } diff --git a/src/cons_tuples_impl.rs b/src/cons_tuples_impl.rs index 3cdfe0d18..f2736ad13 100644 --- a/src/cons_tuples_impl.rs +++ b/src/cons_tuples_impl.rs @@ -57,8 +57,8 @@ impl Clone for ConsTuples /// Create an iterator that maps for example iterators of /// `((A, B), C)` to `(A, B, C)`. -pub fn cons_tuples(iterable: I) -> ConsTuples - where I: Iterator +pub fn cons_tuples(iterable: I) -> ConsTuples + where I: IntoIterator { ConsTuples { iter: iterable.into_iter() } } diff --git a/src/format.rs b/src/format.rs index f72ed3917..3a8b2977e 100644 --- a/src/format.rs +++ b/src/format.rs @@ -28,7 +28,7 @@ pub struct Format<'a, I> { inner: RefCell>, } -pub fn new_format<'a, I, F>(iter: I, separator: &'a str, f: F) -> FormatWith<'a, I, F> +pub fn new_format(iter: I, separator: &str, f: F) -> FormatWith<'_, I, F> where I: Iterator, F: FnMut(I::Item, &mut dyn FnMut(&dyn fmt::Display) -> fmt::Result) -> fmt::Result { @@ -38,7 +38,7 @@ pub fn new_format<'a, I, F>(iter: I, separator: &'a str, f: F) -> FormatWith<'a, } } -pub fn new_format_default<'a, I>(iter: I, separator: &'a str) -> Format<'a, I> +pub fn new_format_default(iter: I, separator: &str) -> Format<'_, I> where I: Iterator, { Format { @@ -60,7 +60,7 @@ impl<'a, I, F> fmt::Display for FormatWith<'a, I, F> if let Some(fst) = iter.next() { format(fst, &mut |disp: &dyn fmt::Display| disp.fmt(f))?; for elt in iter { - if self.sep.len() > 0 { + if !self.sep.is_empty() { f.write_str(self.sep)?; } @@ -85,7 +85,7 @@ impl<'a, I> Format<'a, I> if let Some(fst) = iter.next() { cb(&fst, f)?; for elt in iter { - if self.sep.len() > 0 { + if !self.sep.is_empty() { f.write_str(self.sep)?; } cb(&elt, f)?; diff --git a/src/group_map.rs b/src/group_map.rs index 2d219e92a..9787adc7f 100644 --- a/src/group_map.rs +++ b/src/group_map.rs @@ -15,7 +15,7 @@ pub fn into_group_map(iter: I) -> HashMap> let mut lookup = HashMap::new(); for (key, val) in iter { - lookup.entry(key).or_insert(Vec::new()).push(val); + lookup.entry(key).or_insert_with(Vec::new).push(val); } lookup @@ -30,5 +30,3 @@ pub fn into_group_map_by(iter: I, f: impl Fn(&V) -> K) -> HashMap(iter: I, elt: ElemF) -> IntersperseWith Step where Self: Sized @@ -751,7 +751,7 @@ pub trait Itertools : Iterator { } /// See [`.map_ok()`](#method.map_ok). - #[deprecated(note="Use .map_ok() instead", since="0.10")] + #[deprecated(note="Use .map_ok() instead", since="0.10.0")] fn map_results(self, f: F) -> MapOk where Self: Iterator> + Sized, F: FnMut(T) -> U, @@ -1651,7 +1651,7 @@ pub trait Itertools : Iterator { /// /// itertools::assert_equal(rx.iter(), vec![1, 3, 5, 7, 9]); /// ``` - #[deprecated(note="Use .for_each() instead", since="0.8")] + #[deprecated(note="Use .for_each() instead", since="0.8.0")] fn foreach(self, f: F) where F: FnMut(Self::Item), Self: Sized, @@ -1839,7 +1839,7 @@ pub trait Itertools : Iterator { } /// See [`.fold_ok()`](#method.fold_ok). - #[deprecated(note="Use .fold_ok() instead", since="0.10")] + #[deprecated(note="Use .fold_ok() instead", since="0.10.0")] fn fold_results(&mut self, start: B, f: F) -> Result where Self: Iterator>, F: FnMut(B, A) -> B @@ -2099,13 +2099,13 @@ 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")] + #[deprecated(note="Use .try_fold() instead", since="0.8.0")] fn fold_while(&mut self, init: B, mut f: F) -> FoldWhile where Self: Sized, F: FnMut(B, Self::Item) -> FoldWhile { let mut acc = init; - while let Some(item) = self.next() { + for item in self { match f(acc, item) { FoldWhile::Continue(res) => acc = res, res @ FoldWhile::Done(_) => return res, diff --git a/src/size_hint.rs b/src/size_hint.rs index be54443f2..9d9b8b8a1 100644 --- a/src/size_hint.rs +++ b/src/size_hint.rs @@ -10,7 +10,7 @@ pub type SizeHint = (usize, Option); /// Add **SizeHint** correctly. #[inline] pub fn add(a: SizeHint, b: SizeHint) -> SizeHint { - let min = a.0.checked_add(b.0).unwrap_or(usize::MAX); + let min = a.0.saturating_add(b.0); let max = match (a.1, b.1) { (Some(x), Some(y)) => x.checked_add(y), _ => None, @@ -56,7 +56,7 @@ pub fn sub_scalar(sh: SizeHint, x: usize) -> SizeHint { /// ``` #[inline] pub fn mul(a: SizeHint, b: SizeHint) -> SizeHint { - let low = a.0.checked_mul(b.0).unwrap_or(usize::MAX); + let low = a.0.saturating_mul(b.0); let hi = match (a.1, b.1) { (Some(x), Some(y)) => x.checked_mul(y), (Some(0), None) | (None, Some(0)) => Some(0), diff --git a/src/sources.rs b/src/sources.rs index 270b6ca37..5bb6afe4a 100644 --- a/src/sources.rs +++ b/src/sources.rs @@ -7,7 +7,7 @@ use std::mem; /// See [`repeat_call`](../fn.repeat_call.html) for more information. #[derive(Clone)] -#[deprecated(note="Use std repeat_with() instead", since="0.8")] +#[deprecated(note="Use std repeat_with() instead", since="0.8.0")] pub struct RepeatCall { f: F, } @@ -39,7 +39,7 @@ impl fmt::Debug for RepeatCall /// vec![1, 1, 1, 1, 1] /// ); /// ``` -#[deprecated(note="Use std repeat_with() instead", since="0.8")] +#[deprecated(note="Use std repeat_with() instead", since="0.8.0")] pub fn repeat_call(function: F) -> RepeatCall where F: FnMut() -> A { diff --git a/src/tuple_impl.rs b/src/tuple_impl.rs index 4388e71e3..784830645 100644 --- a/src/tuple_impl.rs +++ b/src/tuple_impl.rs @@ -57,12 +57,12 @@ impl Iterator for TupleBuffer fn size_hint(&self) -> (usize, Option) { let buffer = &self.buf.as_ref()[self.cur..]; - let len = if buffer.len() == 0 { + let len = if buffer.is_empty() { 0 } else { buffer.iter() .position(|x| x.is_none()) - .unwrap_or(buffer.len()) + .unwrap_or_else(|| buffer.len()) }; (len, Some(len)) } @@ -212,7 +212,7 @@ pub fn circular_tuple_windows(iter: I) -> CircularTupleWindows let iter = tuple_windows(iter.cycle()).take(len); CircularTupleWindows { - iter: iter, + iter, phantom_data: PhantomData{} } }