1.0.0[][src]Trait prcn_lib::prelude::__std_iter::IntoIterator

pub trait IntoIterator where
    <Self::IntoIter as Iterator>::Item == Self::Item
{ type Item; type IntoIter: Iterator; fn into_iter(self) -> Self::IntoIter; }

Conversion into an Iterator.

By implementing IntoIterator for a type, you define how it will be converted to an iterator. This is common for types which describe a collection of some kind.

One benefit of implementing IntoIterator is that your type will work with Rust's for loop syntax.

See also: FromIterator.

Examples

Basic usage:

let v = vec![1, 2, 3];
let mut iter = v.into_iter();

assert_eq!(Some(1), iter.next());
assert_eq!(Some(2), iter.next());
assert_eq!(Some(3), iter.next());
assert_eq!(None, iter.next());

Implementing IntoIterator for your type:

// A sample collection, that's just a wrapper over Vec<T>
#[derive(Debug)]
struct MyCollection(Vec<i32>);

// Let's give it some methods so we can create one and add things
// to it.
impl MyCollection {
    fn new() -> MyCollection {
        MyCollection(Vec::new())
    }

    fn add(&mut self, elem: i32) {
        self.0.push(elem);
    }
}

// and we'll implement IntoIterator
impl IntoIterator for MyCollection {
    type Item = i32;
    type IntoIter = std::vec::IntoIter<Self::Item>;

    fn into_iter(self) -> Self::IntoIter {
        self.0.into_iter()
    }
}

// Now we can make a new collection...
let mut c = MyCollection::new();

// ... add some stuff to it ...
c.add(0);
c.add(1);
c.add(2);

// ... and then turn it into an Iterator:
for (i, n) in c.into_iter().enumerate() {
    assert_eq!(i as i32, n);
}

It is common to use IntoIterator as a trait bound. This allows the input collection type to change, so long as it is still an iterator. Additional bounds can be specified by restricting on Item:

fn collect_as_strings<T>(collection: T) -> Vec<String>
where
    T: IntoIterator,
    T::Item: std::fmt::Debug,
{
    collection
        .into_iter()
        .map(|item| format!("{:?}", item))
        .collect()
}

Associated Types

type Item

The type of the elements being iterated over.

type IntoIter: Iterator

Which kind of iterator are we turning this into?

Loading content...

Required methods

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value.

See the module-level documentation for more.

Examples

Basic usage:

let v = vec![1, 2, 3];
let mut iter = v.into_iter();

assert_eq!(Some(1), iter.next());
assert_eq!(Some(2), iter.next());
assert_eq!(Some(3), iter.next());
assert_eq!(None, iter.next());
Loading content...

Implementations on Foreign Types

impl<'a, T> IntoIterator for &'a Receiver<T>[src]

type Item = T

type IntoIter = Iter<'a, T>

impl<'a> IntoIterator for &'a Path[src]

type Item = &'a OsStr

type IntoIter = Iter<'a>

impl<T> IntoIterator for Receiver<T>[src]

type Item = T

type IntoIter = IntoIter<T>

impl<'a> IntoIterator for &'a UnixListener[src]

impl<'a> IntoIterator for &'a PathBuf[src]

type Item = &'a OsStr

type IntoIter = Iter<'a>

impl<T, E> IntoIterator for Result<T, E>[src]

type Item = T

type IntoIter = IntoIter<T>

fn into_iter(self) -> IntoIter<T>[src]

Returns a consuming iterator over the possibly contained value.

The iterator yields one value if the result is Result::Ok, otherwise none.

Examples

Basic usage:

let x: Result<u32, &str> = Ok(5);
let v: Vec<u32> = x.into_iter().collect();
assert_eq!(v, [5]);

let x: Result<u32, &str> = Err("nothing!");
let v: Vec<u32> = x.into_iter().collect();
assert_eq!(v, []);

impl<'a, const N: usize, T> IntoIterator for &'a [T; N] where
    [T; N]: LengthAtMost32
[src]

type Item = &'a T

type IntoIter = Iter<'a, T>

impl<T> IntoIterator for Option<T>[src]

type Item = T

type IntoIter = IntoIter<T>

fn into_iter(self) -> IntoIter<T>[src]

Returns a consuming iterator over the possibly contained value.

Examples

let x = Some("string");
let v: Vec<&str> = x.into_iter().collect();
assert_eq!(v, ["string"]);

let x = None;
let v: Vec<&str> = x.into_iter().collect();
assert!(v.is_empty());

impl<'a, T, E> IntoIterator for &'a mut Result<T, E>[src]

type Item = &'a mut T

type IntoIter = IterMut<'a, T>

impl<'a, T> IntoIterator for &'a [T][src]

type Item = &'a T

type IntoIter = Iter<'a, T>

impl<'a, T> IntoIterator for &'a mut [T][src]

type Item = &'a mut T

type IntoIter = IterMut<'a, T>

impl<'a, T, E> IntoIterator for &'a Result<T, E>[src]

type Item = &'a T

type IntoIter = Iter<'a, T>

impl<'a, T> IntoIterator for &'a Option<T>[src]

type Item = &'a T

type IntoIter = Iter<'a, T>

impl<'a, T> IntoIterator for &'a mut Option<T>[src]

type Item = &'a mut T

type IntoIter = IterMut<'a, T>

impl<'a, const N: usize, T> IntoIterator for &'a mut [T; N] where
    [T; N]: LengthAtMost32
[src]

type Item = &'a mut T

type IntoIter = IterMut<'a, T>

impl<'a, T> IntoIterator for &'a BinaryHeap<T>[src]

type Item = &'a T

type IntoIter = Iter<'a, T>

impl<'a, T> IntoIterator for &'a mut LinkedList<T>[src]

type Item = &'a mut T

type IntoIter = IterMut<'a, T>

impl<T> IntoIterator for Vec<T>[src]

type Item = T

type IntoIter = IntoIter<T>

fn into_iter(self) -> IntoIter<T>[src]

Creates a consuming iterator, that is, one that moves each value out of the vector (from start to end). The vector cannot be used after calling this.

Examples

let v = vec!["a".to_string(), "b".to_string()];
for s in v.into_iter() {
    // s has type String, not &String
    println!("{}", s);
}

impl<'a, T> IntoIterator for &'a Vec<T>[src]

type Item = &'a T

type IntoIter = Iter<'a, T>

impl<'a, T> IntoIterator for &'a mut Vec<T>[src]

type Item = &'a mut T

type IntoIter = IterMut<'a, T>

impl<'a, T> IntoIterator for &'a LinkedList<T>[src]

type Item = &'a T

type IntoIter = Iter<'a, T>

impl<T> IntoIterator for LinkedList<T>[src]

type Item = T

type IntoIter = IntoIter<T>

fn into_iter(self) -> IntoIter<T>[src]

Consumes the list into an iterator yielding elements by value.

impl<T> IntoIterator for BinaryHeap<T>[src]

type Item = T

type IntoIter = IntoIter<T>

fn into_iter(self) -> IntoIter<T>[src]

Creates a consuming iterator, that is, one that moves each value out of the binary heap in arbitrary order. The binary heap cannot be used after calling this.

Examples

Basic usage:

use std::collections::BinaryHeap;
let heap = BinaryHeap::from(vec![1, 2, 3, 4]);

// Print 1, 2, 3, 4 in arbitrary order
for x in heap.into_iter() {
    // x has type i32, not &i32
    println!("{}", x);
}

impl<T, S> IntoIterator for HashSet<T, S>

type Item = T

type IntoIter = IntoIter<T>

fn into_iter(self) -> IntoIter<T>

Creates a consuming iterator, that is, one that moves each value out of the set in arbitrary order. The set cannot be used after calling this.

Examples

use hashbrown::HashSet;
let mut set = HashSet::new();
set.insert("a".to_string());
set.insert("b".to_string());

// Not possible to collect to a Vec<String> with a regular `.iter()`.
let v: Vec<String> = set.into_iter().collect();

// Will print in an arbitrary order.
for x in &v {
    println!("{}", x);
}

impl<'a, K, V, S> IntoIterator for &'a HashMap<K, V, S>

type Item = (&'a K, &'a V)

type IntoIter = Iter<'a, K, V>

impl<'a, K, V, S> IntoIterator for &'a mut HashMap<K, V, S>

type Item = (&'a K, &'a mut V)

type IntoIter = IterMut<'a, K, V>

impl<'a, T, S> IntoIterator for &'a HashSet<T, S>

type Item = &'a T

type IntoIter = Iter<'a, T>

impl<K, V, S> IntoIterator for HashMap<K, V, S>

type Item = (K, V)

type IntoIter = IntoIter<K, V>

fn into_iter(self) -> IntoIter<K, V>

Creates a consuming iterator, that is, one that moves each key-value pair out of the map in arbitrary order. The map cannot be used after calling this.

Examples

use hashbrown::HashMap;

let mut map = HashMap::new();
map.insert("a", 1);
map.insert("b", 2);
map.insert("c", 3);

// Not possible with .iter()
let vec: Vec<(&str, i32)> = map.into_iter().collect();

impl<'a> IntoIterator for &'a AsciiStr[src]

Produces references for compatibility with [u8].

(str doesn't implement IntoIterator for its references, so there is no compatibility to lose.)

type Item = &'a AsciiChar

type IntoIter = CharsRef<'a>

impl<'a> IntoIterator for &'a mut AsciiStr[src]

type Item = &'a mut AsciiChar

type IntoIter = CharsMut<'a>

impl<A, S> IntoIterator for HashSet<A, S> where
    A: Hash + Eq + Clone,
    S: BuildHasher
[src]

type Item = A

type IntoIter = ConsumingIter<<HashSet<A, S> as IntoIterator>::Item>

impl<K, V, S> IntoIterator for HashMap<K, V, S> where
    K: Hash + Eq + Clone,
    S: BuildHasher,
    V: Clone
[src]

type Item = (K, V)

type IntoIter = ConsumingIter<(K, V)>

impl<'a, A> IntoIterator for &'a Vector<A> where
    A: Clone
[src]

type Item = &'a A

type IntoIter = Iter<'a, A>

impl<A> IntoIterator for Vector<A> where
    A: Clone
[src]

type Item = A

type IntoIter = ConsumingIter<A>

impl<'a, A> IntoIterator for &'a OrdSet<A> where
    A: 'a + Ord
[src]

type Item = &'a A

type IntoIter = Iter<'a, A>

impl<'a, K, V, S> IntoIterator for &'a HashMap<K, V, S> where
    K: Hash + Eq,
    S: BuildHasher
[src]

type Item = &'a (K, V)

type IntoIter = Iter<'a, K, V>

impl<'a, A> IntoIterator for FocusMut<'a, A> where
    A: Clone + 'a, 
[src]

type Item = &'a mut A

type IntoIter = IterMut<'a, A>

impl<'a, A> IntoIterator for Focus<'a, A> where
    A: Clone + 'a, 
[src]

type Item = &'a A

type IntoIter = Iter<'a, A>

impl<A> IntoIterator for OrdSet<A> where
    A: Ord + Clone
[src]

type Item = A

type IntoIter = ConsumingIter<A>

impl<'a, A, S> IntoIterator for &'a HashSet<A, S> where
    A: Hash + Eq,
    S: BuildHasher
[src]

type Item = &'a A

type IntoIter = Iter<'a, A>

impl<'a, K, V> IntoIterator for &'a OrdMap<K, V> where
    K: Ord
[src]

type Item = &'a (K, V)

type IntoIter = Iter<'a, (K, V)>

impl<K, V> IntoIterator for OrdMap<K, V> where
    K: Ord + Clone,
    V: Clone
[src]

type Item = (K, V)

type IntoIter = ConsumingIter<(K, V)>

impl<'a, A, N> IntoIterator for &'a mut Chunk<A, N> where
    N: ChunkLength<A>, 

type Item = &'a mut A

type IntoIter = IterMut<'a, A>

impl<A, N> IntoIterator for SparseChunk<A, N> where
    N: ChunkLength<A> + Bits, 

type Item = A

type IntoIter = Drain<A, N>

impl<A, T> IntoIterator for InlineArray<A, T>

type Item = A

type IntoIter = Iter<A, T>

impl<A, N> IntoIterator for RingBuffer<A, N> where
    N: ChunkLength<A>, 

type Item = A

type IntoIter = OwnedIter<A, N>

impl<'a, A, N> IntoIterator for &'a Chunk<A, N> where
    N: ChunkLength<A>, 

type Item = &'a A

type IntoIter = Iter<'a, A>

impl<'a, 'b, A, N> IntoIterator for &'a mut SliceMut<'a, A, N> where
    A: 'a,
    N: 'a + ChunkLength<A>, 

type Item = &'a mut A

type IntoIter = IterMut<'a, A, N>

impl<'a, A, N> IntoIterator for &'a Slice<'a, A, N> where
    A: 'a,
    N: 'a + ChunkLength<A>, 

type Item = &'a A

type IntoIter = Iter<'a, A, N>

impl<'a, A, T> IntoIterator for &'a mut InlineArray<A, T>

type Item = &'a mut A

type IntoIter = IterMut<'a, A>

impl<A, N> IntoIterator for Chunk<A, N> where
    N: ChunkLength<A>, 

type Item = A

type IntoIter = Iter<A, N>

impl<'a, A, N> IntoIterator for &'a mut RingBuffer<A, N> where
    N: ChunkLength<A>, 

type Item = &'a mut A

type IntoIter = IterMut<'a, A, N>

impl<'a, A, N> IntoIterator for &'a RingBuffer<A, N> where
    N: ChunkLength<A>, 

type Item = &'a A

type IntoIter = Iter<'a, A, N>

impl<'a, A, T> IntoIterator for &'a InlineArray<A, T>

type Item = &'a A

type IntoIter = Iter<'a, A>

impl<'a, 'b, A, N> IntoIterator for &'a SliceMut<'a, A, N> where
    A: 'a,
    N: 'a + ChunkLength<A>, 

type Item = &'a A

type IntoIter = Iter<'a, A, N>

impl<'a, Size> IntoIterator for &'a Bitmap<Size> where
    Size: Bits, 

type Item = usize

type IntoIter = Iter<'a, Size>

impl<T, S> IntoIterator for IndexSet<T, S> where
    S: BuildHasher,
    T: Hash + Eq
[src]

type Item = T

type IntoIter = IntoIter<T>

impl<'a, T, S> IntoIterator for &'a IndexSet<T, S> where
    S: BuildHasher,
    T: Hash + Eq
[src]

type Item = &'a T

type IntoIter = Iter<'a, T>

impl<'a, K, V, S> IntoIterator for &'a mut IndexMap<K, V, S> where
    K: Hash + Eq,
    S: BuildHasher
[src]

type Item = (&'a K, &'a mut V)

type IntoIter = IterMut<'a, K, V>

impl<'a, K, V, S> IntoIterator for &'a IndexMap<K, V, S> where
    K: Hash + Eq,
    S: BuildHasher
[src]

type Item = (&'a K, &'a V)

type IntoIter = Iter<'a, K, V>

impl<K, V, S> IntoIterator for IndexMap<K, V, S> where
    K: Hash + Eq,
    S: BuildHasher
[src]

type Item = (K, V)

type IntoIter = IntoIter<K, V>

impl<'a, N, R, C, S> IntoIterator for &'a mut Matrix<N, R, C, S> where
    C: Dim,
    N: Scalar,
    R: Dim,
    S: StorageMut<N, R, C>, 
[src]

type Item = &'a mut N

type IntoIter = MatrixIterMut<'a, N, R, C, S>

impl<'a, N, R, C, S> IntoIterator for &'a Matrix<N, R, C, S> where
    C: Dim,
    N: Scalar,
    R: Dim,
    S: Storage<N, R, C>, 
[src]

type Item = &'a N

type IntoIter = MatrixIter<'a, N, R, C, S>

impl<'a, T, N> IntoIterator for &'a mut GenericArray<T, N> where
    N: ArrayLength<T>,
    T: 'a, 

type IntoIter = IterMut<'a, T>

type Item = &'a mut T

impl<'a, T, N> IntoIterator for &'a GenericArray<T, N> where
    N: ArrayLength<T>,
    T: 'a, 

type IntoIter = Iter<'a, T>

type Item = &'a T

impl<T, N> IntoIterator for GenericArray<T, N> where
    N: ArrayLength<T>, 

type Item = T

type IntoIter = GenericArrayIter<T, N>

impl<'a, A, D> IntoIterator for Lanes<'a, A, D> where
    D: Dimension
[src]

type Item = <<Lanes<'a, A, D> as IntoIterator>::IntoIter as Iterator>::Item

type IntoIter = LanesIter<'a, A, D>

impl<'a, A, D> IntoIterator for Windows<'a, A, D> where
    A: 'a,
    D: Dimension
[src]

type Item = <<Windows<'a, A, D> as IntoIterator>::IntoIter as Iterator>::Item

type IntoIter = WindowsIter<'a, A, D>

impl<'a, A, D> IntoIterator for ArrayBase<ViewRepr<&'a mut A>, D> where
    D: Dimension
[src]

type Item = &'a mut A

type IntoIter = IterMut<'a, A, D>

impl<'a> IntoIterator for &'a IxDynImpl[src]

impl<D> IntoIterator for Indices<D> where
    D: Dimension
[src]

impl<'a, A, D> IntoIterator for LanesMut<'a, A, D> where
    D: Dimension
[src]

type Item = <<LanesMut<'a, A, D> as IntoIterator>::IntoIter as Iterator>::Item

type IntoIter = LanesIterMut<'a, A, D>

impl<'a, S, D> IntoIterator for &'a ArrayBase<S, D> where
    D: Dimension,
    S: Data
[src]

type Item = &'a <S as RawData>::Elem

type IntoIter = Iter<'a, <S as RawData>::Elem, D>

impl<'a, S, D> IntoIterator for &'a mut ArrayBase<S, D> where
    D: Dimension,
    S: DataMut
[src]

type Item = &'a mut <S as RawData>::Elem

type IntoIter = IterMut<'a, <S as RawData>::Elem, D>

impl<'a, A, D> IntoIterator for ExactChunks<'a, A, D> where
    A: 'a,
    D: Dimension
[src]

type Item = <<ExactChunks<'a, A, D> as IntoIterator>::IntoIter as Iterator>::Item

type IntoIter = ExactChunksIter<'a, A, D>

impl<'a, A, D> IntoIterator for ExactChunksMut<'a, A, D> where
    A: 'a,
    D: Dimension
[src]

type Item = <<ExactChunksMut<'a, A, D> as IntoIterator>::IntoIter as Iterator>::Item

type IntoIter = ExactChunksIterMut<'a, A, D>

impl<'a, A, D> IntoIterator for ArrayBase<ViewRepr<&'a A>, D> where
    D: Dimension
[src]

type Item = &'a A

type IntoIter = Iter<'a, A, D>

impl IntoIterator for SetMatches[src]

impl<'a> IntoIterator for &'a SetMatches[src]

impl<'a> IntoIterator for &'a SetMatches[src]

impl IntoIterator for SetMatches[src]

impl<'a> IntoIterator for &'a Utf8Sequence

type IntoIter = Iter<'a, Utf8Range>

type Item = &'a Utf8Range

impl<'a, T> IntoIterator for &'a mut ThreadLocal<T> where
    T: 'a + Send

type Item = &'a mut T

type IntoIter = IterMut<'a, T>

impl<T> IntoIterator for CachedThreadLocal<T> where
    T: Send

type Item = T

type IntoIter = CachedIntoIter<T>

impl<'a, T> IntoIterator for &'a mut CachedThreadLocal<T> where
    T: 'a + Send

type Item = &'a mut T

type IntoIter = CachedIterMut<'a, T>

impl<T> IntoIterator for ThreadLocal<T> where
    T: Send

type Item = T

type IntoIter = IntoIter<T>

impl<'a, A> IntoIterator for &'a mut SmallVec<A> where
    A: Array
[src]

type IntoIter = IterMut<'a, <A as Array>::Item>

type Item = &'a mut <A as Array>::Item

impl<'a, A> IntoIterator for &'a SmallVec<A> where
    A: Array
[src]

type IntoIter = Iter<'a, <A as Array>::Item>

type Item = &'a <A as Array>::Item

impl<A> IntoIterator for SmallVec<A> where
    A: Array
[src]

type IntoIter = IntoIter<A>

type Item = <A as Array>::Item

Loading content...

Implementors

impl<'a, I> IntoIterator for &'a IntoChunks<I> where
    I: Iterator,
    <I as Iterator>::Item: 'a, 
[src]

type Item = Chunk<'a, I>

type IntoIter = Chunks<'a, I>

impl<'a, I> IntoIterator for &'a RcIter<I> where
    I: Iterator
[src]

Return an iterator from &RcIter<I> (by simply cloning it).

type Item = <I as Iterator>::Item

type IntoIter = RcIter<I>

impl<'a, K, I, F> IntoIterator for &'a GroupBy<K, I, F> where
    F: FnMut(&<I as Iterator>::Item) -> K,
    I: Iterator,
    K: PartialEq<K>,
    <I as Iterator>::Item: 'a, 
[src]

type Item = (K, Group<'a, K, I, F>)

type IntoIter = Groups<'a, K, I, F>

impl<'a, K, V> IntoIterator for &'a BTreeMap<K, V> where
    K: 'a,
    V: 'a, 
[src]

type Item = (&'a K, &'a V)

type IntoIter = Iter<'a, K, V>

impl<'a, K, V> IntoIterator for &'a mut BTreeMap<K, V> where
    K: 'a,
    V: 'a, 
[src]

type Item = (&'a K, &'a mut V)

type IntoIter = IterMut<'a, K, V>

impl<'a, K, V, S> IntoIterator for &'a prcn_lib::prelude::HashMap<K, V, S>[src]

type Item = (&'a K, &'a V)

type IntoIter = Iter<'a, K, V>

impl<'a, K, V, S> IntoIterator for &'a mut prcn_lib::prelude::HashMap<K, V, S>[src]

type Item = (&'a K, &'a mut V)

type IntoIter = IterMut<'a, K, V>

impl<'a, T> IntoIterator for &'a BTreeSet<T>[src]

type Item = &'a T

type IntoIter = Iter<'a, T>

impl<'a, T> IntoIterator for &'a VecDeque<T>[src]

type Item = &'a T

type IntoIter = Iter<'a, T>

impl<'a, T> IntoIterator for &'a mut VecDeque<T>[src]

type Item = &'a mut T

type IntoIter = IterMut<'a, T>

impl<'a, T, S> IntoIterator for &'a prcn_lib::prelude::HashSet<T, S>[src]

type Item = &'a T

type IntoIter = Iter<'a, T>

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

type IntoIter = I

impl<K, V> IntoIterator for BTreeMap<K, V>[src]

type Item = (K, V)

type IntoIter = IntoIter<K, V>

impl<K, V, S> IntoIterator for prcn_lib::prelude::HashMap<K, V, S>[src]

type Item = (K, V)

type IntoIter = IntoIter<K, V>

fn into_iter(self) -> IntoIter<K, V>[src]

Creates a consuming iterator, that is, one that moves each key-value pair out of the map in arbitrary order. The map cannot be used after calling this.

Examples

use std::collections::HashMap;

let mut map = HashMap::new();
map.insert("a", 1);
map.insert("b", 2);
map.insert("c", 3);

// Not possible with .iter()
let vec: Vec<(&str, i32)> = map.into_iter().collect();

impl<T> IntoIterator for BTreeSet<T>[src]

type Item = T

type IntoIter = IntoIter<T>

fn into_iter(self) -> IntoIter<T>[src]

Gets an iterator for moving out the BTreeSet's contents.

Examples

use std::collections::BTreeSet;

let set: BTreeSet<usize> = [1, 2, 3, 4].iter().cloned().collect();

let v: Vec<_> = set.into_iter().collect();
assert_eq!(v, [1, 2, 3, 4]);

impl<T> IntoIterator for VecDeque<T>[src]

type Item = T

type IntoIter = IntoIter<T>

fn into_iter(self) -> IntoIter<T>[src]

Consumes the VecDeque into a front-to-back iterator yielding elements by value.

impl<T, S> IntoIterator for prcn_lib::prelude::HashSet<T, S>[src]

type Item = T

type IntoIter = IntoIter<T>

fn into_iter(self) -> IntoIter<T>[src]

Creates a consuming iterator, that is, one that moves each value out of the set in arbitrary order. The set cannot be used after calling this.

Examples

use std::collections::HashSet;
let mut set = HashSet::new();
set.insert("a".to_string());
set.insert("b".to_string());

// Not possible to collect to a Vec<String> with a regular `.iter()`.
let v: Vec<String> = set.into_iter().collect();

// Will print in an arbitrary order.
for x in &v {
    println!("{}", x);
}
Loading content...