use core::prelude::*;
use core::default::Default;
-use core::iter::FromIterator;
+use core::iter::{FromIterator, IntoIterator};
use core::mem::{zeroed, replace, swap};
use core::ptr;
}
}
+impl<T> IntoIterator for BinaryHeap<T> {
+ type Iter = IntoIter<T>;
+
+ fn into_iter(self) -> IntoIter<T> {
+ self.into_iter()
+ }
+}
+
+impl<'a, T> IntoIterator for &'a BinaryHeap<T> where T: Ord {
+ type Iter = Iter<'a, T>;
+
+ fn into_iter(self) -> Iter<'a, T> {
+ self.iter()
+ }
+}
+
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Ord> Extend<T> for BinaryHeap<T> {
fn extend<Iter: Iterator<Item=T>>(&mut self, mut iter: Iter) {
use core::hash;
use core::iter::RandomAccessIterator;
use core::iter::{Chain, Enumerate, Repeat, Skip, Take, repeat, Cloned};
-use core::iter::{self, FromIterator};
+use core::iter::{self, FromIterator, IntoIterator};
use core::num::Int;
use core::ops::Index;
use core::slice;
}
}
+impl<'a> IntoIterator for &'a Bitv {
+ type Iter = Iter<'a>;
+
+ fn into_iter(self) -> Iter<'a> {
+ self.iter()
+ }
+}
+
/// An implementation of a set using a bit vector as an underlying
/// representation for holding unsigned numerical elements.
///
#[inline] fn size_hint(&self) -> (uint, Option<uint>) { self.0.size_hint() }
}
+impl<'a> IntoIterator for &'a BitvSet {
+ type Iter = SetIter<'a>;
+
+ fn into_iter(self) -> SetIter<'a> {
+ self.iter()
+ }
+}
#[cfg(test)]
mod tests {
use core::default::Default;
use core::fmt::Debug;
use core::hash::{Hash, Hasher};
-use core::iter::{Map, FromIterator};
+use core::iter::{Map, FromIterator, IntoIterator};
use core::ops::{Index, IndexMut};
use core::{iter, fmt, mem};
use Bound::{self, Included, Excluded, Unbounded};
}
}
+impl<K, V> IntoIterator for BTreeMap<K, V> {
+ type Iter = IntoIter<K, V>;
+
+ fn into_iter(self) -> IntoIter<K, V> {
+ self.into_iter()
+ }
+}
+
+impl<'a, K, V> IntoIterator for &'a BTreeMap<K, V> {
+ type Iter = Iter<'a, K, V>;
+
+ fn into_iter(self) -> Iter<'a, K, V> {
+ self.iter()
+ }
+}
+
+impl<'a, K, V> IntoIterator for &'a mut BTreeMap<K, V> {
+ type Iter = IterMut<'a, K, V>;
+
+ fn into_iter(mut self) -> IterMut<'a, K, V> {
+ self.iter_mut()
+ }
+}
+
/// A helper enum useful for deciding whether to continue a loop since we can't
/// return from a closure
enum Continuation<A, B> {
use core::default::Default;
use core::fmt::Debug;
use core::fmt;
-use core::iter::{Peekable, Map, FromIterator};
+use core::iter::{Peekable, Map, FromIterator, IntoIterator};
use core::ops::{BitOr, BitAnd, BitXor, Sub};
use btree_map::{BTreeMap, Keys};
}
}
+impl<T> IntoIterator for BTreeSet<T> {
+ type Iter = IntoIter<T>;
+
+ fn into_iter(self) -> IntoIter<T> {
+ self.into_iter()
+ }
+}
+
+impl<'a, T> IntoIterator for &'a BTreeSet<T> {
+ type Iter = Iter<'a, T>;
+
+ fn into_iter(self) -> Iter<'a, T> {
+ self.iter()
+ }
+}
+
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Ord> Extend<T> for BTreeSet<T> {
#[inline]
use core::default::Default;
use core::fmt;
use core::hash::{Writer, Hasher, Hash};
-use core::iter::{self, FromIterator};
+use core::iter::{self, FromIterator, IntoIterator};
use core::mem;
use core::ptr;
}
}
+impl<T> IntoIterator for DList<T> {
+ type Iter = IntoIter<T>;
+
+ fn into_iter(self) -> IntoIter<T> {
+ self.into_iter()
+ }
+}
+
+impl<'a, T> IntoIterator for &'a DList<T> {
+ type Iter = Iter<'a, T>;
+
+ fn into_iter(self) -> Iter<'a, T> {
+ self.iter()
+ }
+}
+
+impl<'a, T> IntoIterator for &'a mut DList<T> {
+ type Iter = IterMut<'a, T>;
+
+ fn into_iter(mut self) -> IterMut<'a, T> {
+ self.iter_mut()
+ }
+}
+
#[stable(feature = "rust1", since = "1.0.0")]
impl<A> Extend<A> for DList<A> {
fn extend<T: Iterator<Item=A>>(&mut self, mut iterator: T) {
use core::prelude::*;
use core::fmt;
use core::num::Int;
-use core::iter::FromIterator;
+use core::iter::{FromIterator, IntoIterator};
use core::ops::{Sub, BitOr, BitAnd, BitXor};
// FIXME(contentions): implement union family of methods? (general design may be wrong here)
}
}
+impl<'a, E> IntoIterator for &'a EnumSet<E> where E: CLike {
+ type Iter = Iter<E>;
+
+ fn into_iter(self) -> Iter<E> {
+ self.iter()
+ }
+}
+
impl<E:CLike> Extend<E> for EnumSet<E> {
fn extend<I: Iterator<Item=E>>(&mut self, mut iterator: I) {
for element in iterator {
use core::cmp::Ordering;
use core::default::Default;
use core::fmt;
-use core::iter::{self, repeat, FromIterator, RandomAccessIterator};
+use core::iter::{self, repeat, FromIterator, IntoIterator, RandomAccessIterator};
use core::marker;
use core::mem;
use core::num::{Int, UnsignedInt};
}
}
+impl<T> IntoIterator for RingBuf<T> {
+ type Iter = IntoIter<T>;
+
+ fn into_iter(self) -> IntoIter<T> {
+ self.into_iter()
+ }
+}
+
+impl<'a, T> IntoIterator for &'a RingBuf<T> {
+ type Iter = Iter<'a, T>;
+
+ fn into_iter(self) -> Iter<'a, T> {
+ self.iter()
+ }
+}
+
+impl<'a, T> IntoIterator for &'a mut RingBuf<T> {
+ type Iter = IterMut<'a, T>;
+
+ fn into_iter(mut self) -> IterMut<'a, T> {
+ self.iter_mut()
+ }
+}
+
#[stable(feature = "rust1", since = "1.0.0")]
impl<A> Extend<A> for RingBuf<A> {
fn extend<T: Iterator<Item=A>>(&mut self, mut iterator: T) {
use core::default::Default;
use core::fmt;
use core::hash::{self, Hash};
-use core::iter::{repeat, FromIterator};
+use core::iter::{repeat, FromIterator, IntoIterator};
use core::marker::{ContravariantLifetime, InvariantType};
use core::mem;
use core::nonzero::NonZero;
use core::ops;
use core::ptr;
use core::raw::Slice as RawSlice;
+use core::slice;
use core::uint;
/// A growable list type, written `Vec<T>` but pronounced 'vector.'
}
}
+impl<T> IntoIterator for Vec<T> {
+ type Iter = IntoIter<T>;
+
+ fn into_iter(self) -> IntoIter<T> {
+ self.into_iter()
+ }
+}
+
+impl<'a, T> IntoIterator for &'a Vec<T> {
+ type Iter = slice::Iter<'a, T>;
+
+ fn into_iter(self) -> slice::Iter<'a, T> {
+ self.iter()
+ }
+}
+
+impl<'a, T> IntoIterator for &'a mut Vec<T> {
+ type Iter = slice::IterMut<'a, T>;
+
+ fn into_iter(mut self) -> slice::IterMut<'a, T> {
+ self.iter_mut()
+ }
+}
+
#[unstable(feature = "collections", reason = "waiting on Extend stability")]
impl<T> Extend<T> for Vec<T> {
#[inline]
use core::default::Default;
use core::fmt;
use core::hash::{Hash, Writer, Hasher};
-use core::iter::{Enumerate, FilterMap, Map, FromIterator};
+use core::iter::{Enumerate, FilterMap, Map, FromIterator, IntoIterator};
use core::iter;
use core::mem::replace;
use core::ops::{Index, IndexMut};
}
}
+impl<T> IntoIterator for VecMap<T> {
+ type Iter = IntoIter<T>;
+
+ fn into_iter(self) -> IntoIter<T> {
+ self.into_iter()
+ }
+}
+
+impl<'a, T> IntoIterator for &'a VecMap<T> {
+ type Iter = Iter<'a, T>;
+
+ fn into_iter(self) -> Iter<'a, T> {
+ self.iter()
+ }
+}
+
+impl<'a, T> IntoIterator for &'a mut VecMap<T> {
+ type Iter = IterMut<'a, T>;
+
+ fn into_iter(mut self) -> IterMut<'a, T> {
+ self.iter_mut()
+ }
+}
+
#[stable(feature = "rust1", since = "1.0.0")]
impl<V> Extend<(uint, V)> for VecMap<V> {
fn extend<Iter: Iterator<Item=(uint, V)>>(&mut self, mut iter: Iter) {
use cmp::{PartialEq, Eq, PartialOrd, Ord, Ordering};
use fmt;
use hash::{Hash, Hasher, self};
+use iter::IntoIterator;
use marker::Copy;
#[cfg(stage0)]
use ops::{Deref, FullRange};
#[cfg(not(stage0))]
use ops::Deref;
use option::Option;
+use slice::{Iter, IterMut, SliceExt};
// macro for implementing n-ary tuple functions and operations
macro_rules! array_impls {
}
}
+ impl<'a, T> IntoIterator for &'a [T; $N] {
+ type Iter = Iter<'a, T>;
+
+ fn into_iter(self) -> Iter<'a, T> {
+ self.iter()
+ }
+ }
+
+ impl<'a, T> IntoIterator for &'a mut [T; $N] {
+ type Iter = IterMut<'a, T>;
+
+ fn into_iter(self) -> IterMut<'a, T> {
+ self.iter_mut()
+ }
+ }
+
#[stable(feature = "rust1", since = "1.0.0")]
impl<A, B> PartialEq<[B; $N]> for [A; $N] where A: PartialEq<B> {
#[inline]
fn from_iter<T: Iterator<Item=A>>(iterator: T) -> Self;
}
+/// Conversion into an `Iterator`
+#[unstable]
+pub trait IntoIterator {
+ type Iter: Iterator;
+
+ /// Consumes `Self` and returns an iterator over it
+ fn into_iter(self) -> Self::Iter;
+}
+
+impl<I> IntoIterator for I where I: Iterator {
+ type Iter = I;
+
+ fn into_iter(self) -> I {
+ self
+ }
+}
+
/// A type growable from an `Iterator` implementation
#[stable(feature = "rust1", since = "1.0.0")]
pub trait Extend<A> {
// Iterators
//
+impl<'a, T> IntoIterator for &'a [T] {
+ type Iter = Iter<'a, T>;
+
+ fn into_iter(self) -> Iter<'a, T> {
+ self.iter()
+ }
+}
+
+impl<'a, T> IntoIterator for &'a mut [T] {
+ type Iter = IterMut<'a, T>;
+
+ fn into_iter(self) -> IterMut<'a, T> {
+ self.iter_mut()
+ }
+}
+
// The shared definition of the `Iter` and `IterMut` iterators
macro_rules! iterator {
(struct $name:ident -> $ptr:ty, $elem:ty) => {