Trait from_iter::FromIterator[][src]

pub trait FromIterator<A>: Sized {
    fn from_iter<T: IntoIterator<Item = A>>(iter: T) -> Self;
fn try_from_iter<T: IntoIterator<Item = A>>(
        iter: T
    ) -> Result<Self, FromIteratorError>; }
Expand description

This trait contains the from_iter and try_from_iter methods.

Example:

use from_iter::FromIterator;

let iter = (0..).map(|i| i * 2);
let array = <[i32; 8]>::from_iter(iter);
assert_eq!(array, [0, 2, 4, 6, 8, 10, 12, 14]);

Required methods

fn from_iter<T: IntoIterator<Item = A>>(iter: T) -> Self[src]

Expand description

This method fills an array using the given iterator. Note that it will panic if the iterator doesn’t contain enough items.

fn try_from_iter<T: IntoIterator<Item = A>>(
    iter: T
) -> Result<Self, FromIteratorError>
[src]

Expand description

This method fills an array using the given iterator. If there aren’t enough items available, it will return a FromIteratorError.

Loading content...

Implementations on Foreign Types

impl<A, const N: usize> FromIterator<A> for [A; N][src]

fn from_iter<T: IntoIterator<Item = A>>(iter: T) -> Self[src]

fn try_from_iter<T: IntoIterator<Item = A>>(
    iter: T
) -> Result<Self, FromIteratorError>
[src]

Loading content...

Implementors

Loading content...