Auto merge of #32438 - kamalmarhubi:intoiterator-example, r=steveklabnik

style: Use `iter` for IntoIterator parameter names

This commit standardizes the codebase on `iter` for parameters with
IntoIterator bounds.

Previously about 40% of IntoIterator parameters were named `iterable`,
with most of the rest being named `iter`. There was a single place where
it was named `iterator`.
This commit is contained in:
bors 2016-03-28 23:06:09 -07:00
commit 21a4d8098f
9 changed files with 43 additions and 43 deletions

View File

@ -980,13 +980,13 @@ impl<'a, T> IntoIterator for &'a BinaryHeap<T> where T: Ord {
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Ord> Extend<T> for BinaryHeap<T> {
fn extend<I: IntoIterator<Item = T>>(&mut self, iterable: I) {
let iter = iterable.into_iter();
let (lower, _) = iter.size_hint();
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I) {
let iterator = iter.into_iter();
let (lower, _) = iterator.size_hint();
self.reserve(lower);
for elem in iter {
for elem in iterator {
self.push(elem);
}
}

View File

@ -1388,35 +1388,35 @@ impl Clone for String {
#[stable(feature = "rust1", since = "1.0.0")]
impl FromIterator<char> for String {
fn from_iter<I: IntoIterator<Item = char>>(iterable: I) -> String {
fn from_iter<I: IntoIterator<Item = char>>(iter: I) -> String {
let mut buf = String::new();
buf.extend(iterable);
buf.extend(iter);
buf
}
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> FromIterator<&'a str> for String {
fn from_iter<I: IntoIterator<Item = &'a str>>(iterable: I) -> String {
fn from_iter<I: IntoIterator<Item = &'a str>>(iter: I) -> String {
let mut buf = String::new();
buf.extend(iterable);
buf.extend(iter);
buf
}
}
#[stable(feature = "extend_string", since = "1.4.0")]
impl FromIterator<String> for String {
fn from_iter<I: IntoIterator<Item = String>>(iterable: I) -> String {
fn from_iter<I: IntoIterator<Item = String>>(iter: I) -> String {
let mut buf = String::new();
buf.extend(iterable);
buf.extend(iter);
buf
}
}
#[stable(feature = "rust1", since = "1.0.0")]
impl Extend<char> for String {
fn extend<I: IntoIterator<Item = char>>(&mut self, iterable: I) {
let iterator = iterable.into_iter();
fn extend<I: IntoIterator<Item = char>>(&mut self, iter: I) {
let iterator = iter.into_iter();
let (lower_bound, _) = iterator.size_hint();
self.reserve(lower_bound);
for ch in iterator {
@ -1427,15 +1427,15 @@ impl Extend<char> for String {
#[stable(feature = "extend_ref", since = "1.2.0")]
impl<'a> Extend<&'a char> for String {
fn extend<I: IntoIterator<Item = &'a char>>(&mut self, iterable: I) {
self.extend(iterable.into_iter().cloned());
fn extend<I: IntoIterator<Item = &'a char>>(&mut self, iter: I) {
self.extend(iter.into_iter().cloned());
}
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> Extend<&'a str> for String {
fn extend<I: IntoIterator<Item = &'a str>>(&mut self, iterable: I) {
for s in iterable {
fn extend<I: IntoIterator<Item = &'a str>>(&mut self, iter: I) {
for s in iter {
self.push_str(s)
}
}
@ -1443,8 +1443,8 @@ impl<'a> Extend<&'a str> for String {
#[stable(feature = "extend_string", since = "1.4.0")]
impl Extend<String> for String {
fn extend<I: IntoIterator<Item = String>>(&mut self, iterable: I) {
for s in iterable {
fn extend<I: IntoIterator<Item = String>>(&mut self, iter: I) {
for s in iter {
self.push_str(&s)
}
}

View File

@ -1302,13 +1302,13 @@ impl<T> ops::DerefMut for Vec<T> {
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> FromIterator<T> for Vec<T> {
#[inline]
fn from_iter<I: IntoIterator<Item = T>>(iterable: I) -> Vec<T> {
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Vec<T> {
// Unroll the first iteration, as the vector is going to be
// expanded on this iteration in every case when the iterable is not
// empty, but the loop in extend_desugared() is not going to see the
// vector being full in the few subsequent loop iterations.
// So we get better branch prediction.
let mut iterator = iterable.into_iter();
let mut iterator = iter.into_iter();
let mut vector = match iterator.next() {
None => return Vec::new(),
Some(element) => {
@ -1389,8 +1389,8 @@ impl<'a, T> IntoIterator for &'a mut Vec<T> {
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Extend<T> for Vec<T> {
#[inline]
fn extend<I: IntoIterator<Item = T>>(&mut self, iterable: I) {
self.extend_desugared(iterable.into_iter())
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I) {
self.extend_desugared(iter.into_iter())
}
}

View File

@ -2057,8 +2057,8 @@ impl<A> IndexMut<usize> for VecDeque<A> {
#[stable(feature = "rust1", since = "1.0.0")]
impl<A> FromIterator<A> for VecDeque<A> {
fn from_iter<T: IntoIterator<Item = A>>(iterable: T) -> VecDeque<A> {
let iterator = iterable.into_iter();
fn from_iter<T: IntoIterator<Item = A>>(iter: T) -> VecDeque<A> {
let iterator = iter.into_iter();
let (lower, _) = iterator.size_hint();
let mut deq = VecDeque::with_capacity(lower);
deq.extend(iterator);

View File

@ -2458,10 +2458,10 @@ impl<'a, I: Iterator + ?Sized> Iterator for &'a mut I {
///
/// // and we'll implement FromIterator
/// impl FromIterator<i32> for MyCollection {
/// fn from_iter<I: IntoIterator<Item=i32>>(iterator: I) -> Self {
/// fn from_iter<I: IntoIterator<Item=i32>>(iter: I) -> Self {
/// let mut c = MyCollection::new();
///
/// for i in iterator {
/// for i in iter {
/// c.add(i);
/// }
///
@ -2508,7 +2508,7 @@ pub trait FromIterator<A>: Sized {
/// assert_eq!(v, vec![5, 5, 5, 5, 5]);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
fn from_iter<T: IntoIterator<Item=A>>(iterator: T) -> Self;
fn from_iter<T: IntoIterator<Item=A>>(iter: T) -> Self;
}
/// Conversion into an `Iterator`.
@ -2683,11 +2683,11 @@ impl<I: Iterator> IntoIterator for I {
/// // This is a bit simpler with the concrete type signature: we can call
/// // extend on anything which can be turned into an Iterator which gives
/// // us i32s. Because we need i32s to put into MyCollection.
/// fn extend<T: IntoIterator<Item=i32>>(&mut self, iterable: T) {
/// fn extend<T: IntoIterator<Item=i32>>(&mut self, iter: T) {
///
/// // The implementation is very straightforward: loop through the
/// // iterator, and add() each element to ourselves.
/// for elem in iterable {
/// for elem in iter {
/// self.add(elem);
/// }
/// }
@ -2727,7 +2727,7 @@ pub trait Extend<A> {
/// assert_eq!("abcdef", &message);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
fn extend<T: IntoIterator<Item=A>>(&mut self, iterable: T);
fn extend<T: IntoIterator<Item=A>>(&mut self, iter: T);
}
/// An iterator able to yield elements from both ends.

View File

@ -748,7 +748,7 @@ pub struct DecodeUtf16<I>
buf: Option<u16>,
}
/// Create an iterator over the UTF-16 encoded code points in `iterable`,
/// Create an iterator over the UTF-16 encoded code points in `iter`,
/// returning unpaired surrogates as `Err`s.
///
/// # Examples
@ -796,9 +796,9 @@ pub struct DecodeUtf16<I>
/// ```
#[unstable(feature = "decode_utf16", reason = "recently exposed", issue = "27830")]
#[inline]
pub fn decode_utf16<I: IntoIterator<Item = u16>>(iterable: I) -> DecodeUtf16<I::IntoIter> {
pub fn decode_utf16<I: IntoIterator<Item = u16>>(iter: I) -> DecodeUtf16<I::IntoIter> {
DecodeUtf16 {
iter: iterable.into_iter(),
iter: iter.into_iter(),
buf: None,
}
}

View File

@ -1580,11 +1580,11 @@ impl<'a, K: 'a, V: 'a> VacantEntry<'a, K, V> {
impl<K, V, S> FromIterator<(K, V)> for HashMap<K, V, S>
where K: Eq + Hash, S: BuildHasher + Default
{
fn from_iter<T: IntoIterator<Item=(K, V)>>(iterable: T) -> HashMap<K, V, S> {
let iter = iterable.into_iter();
let lower = iter.size_hint().0;
fn from_iter<T: IntoIterator<Item=(K, V)>>(iter: T) -> HashMap<K, V, S> {
let iterator = iter.into_iter();
let lower = iterator.size_hint().0;
let mut map = HashMap::with_capacity_and_hasher(lower, Default::default());
map.extend(iter);
map.extend(iterator);
map
}
}

View File

@ -633,11 +633,11 @@ impl<T, S> FromIterator<T> for HashSet<T, S>
where T: Eq + Hash,
S: BuildHasher + Default,
{
fn from_iter<I: IntoIterator<Item=T>>(iterable: I) -> HashSet<T, S> {
let iter = iterable.into_iter();
let lower = iter.size_hint().0;
fn from_iter<I: IntoIterator<Item=T>>(iter: I) -> HashSet<T, S> {
let iterator = iter.into_iter();
let lower = iterator.size_hint().0;
let mut set = HashSet::with_capacity_and_hasher(lower, Default::default());
set.extend(iter);
set.extend(iterator);
set
}
}

View File

@ -356,8 +356,8 @@ impl FromIterator<CodePoint> for Wtf8Buf {
/// This replaces surrogate code point pairs with supplementary code points,
/// like concatenating ill-formed UTF-16 strings effectively would.
impl Extend<CodePoint> for Wtf8Buf {
fn extend<T: IntoIterator<Item=CodePoint>>(&mut self, iterable: T) {
let iterator = iterable.into_iter();
fn extend<T: IntoIterator<Item=CodePoint>>(&mut self, iter: T) {
let iterator = iter.into_iter();
let (low, _high) = iterator.size_hint();
// Lower bound of one byte per code point (ASCII only)
self.bytes.reserve(low);