diff options
| author | Tobias Bucher <tobiasbucher5991@gmail.com> | 2015-04-06 17:43:50 +0200 |
|---|---|---|
| committer | Tobias Bucher <tobiasbucher5991@gmail.com> | 2015-04-08 00:26:35 +0200 |
| commit | 97f24a85965c3c51a2c18be029091ae52bbd7920 (patch) | |
| tree | 8e601d4b36ac0e3d1320482b959d42af6f8cb891 /src/libcollections | |
| parent | 88427605bbd3271d52d064f339e344da2892b9cb (diff) | |
| download | rust-97f24a85965c3c51a2c18be029091ae52bbd7920.tar.gz rust-97f24a85965c3c51a2c18be029091ae52bbd7920.zip | |
Make `sum` and `product` inherent methods on `Iterator`
In addition to being nicer, this also allows you to use `sum` and `product` for iterators yielding custom types aside from the standard integers. Due to removing the `AdditiveIterator` and `MultiplicativeIterator` trait, this is a breaking change. [breaking-change]
Diffstat (limited to 'src/libcollections')
| -rw-r--r-- | src/libcollections/slice.rs | 3 | ||||
| -rw-r--r-- | src/libcollections/str.rs | 3 |
2 files changed, 2 insertions, 4 deletions
diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index ff923fb1906..8622b8cd935 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -85,7 +85,6 @@ use core::clone::Clone; use core::cmp::Ordering::{self, Greater, Less}; use core::cmp::{self, Ord, PartialEq}; use core::iter::Iterator; -use core::iter::MultiplicativeIterator; use core::marker::Sized; use core::mem::size_of; use core::mem; @@ -1182,7 +1181,7 @@ impl Iterator for ElementSwaps { #[inline] fn size_hint(&self) -> (usize, Option<usize>) { // For a vector of size n, there are exactly n! permutations. - let n = (2..self.sdir.len() + 1).product(); + let n: usize = (2..self.sdir.len() + 1).product(); (n - self.swaps_made, Some(n - self.swaps_made)) } } diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index c22b6fb9286..c5de430ae8c 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -53,7 +53,6 @@ use self::RecompositionState::*; use self::DecompositionType::*; use core::clone::Clone; -use core::iter::AdditiveIterator; use core::iter::{Iterator, Extend}; use core::option::Option::{self, Some, None}; use core::result::Result; @@ -112,7 +111,7 @@ impl<S: AsRef<str>> SliceConcatExt<str, String> for [S] { // this is wrong without the guarantee that `self` is non-empty // `len` calculation may overflow but push_str but will check boundaries let len = sep.len() * (self.len() - 1) - + self.iter().map(|s| s.as_ref().len()).sum(); + + self.iter().map(|s| s.as_ref().len()).sum::<usize>(); let mut result = String::with_capacity(len); let mut first = true; |
