pub trait InternalIterator: Sized {
    type Item;
Show 29 methods fn try_for_each<R, F>(self, f: F) -> ControlFlow<R>
    where
        F: FnMut(Self::Item) -> ControlFlow<R>
; fn find_map<R, F>(self, f: F) -> Option<R>
    where
        F: FnMut(Self::Item) -> Option<R>
, { ... }
fn all<F>(self, f: F) -> bool
    where
        F: FnMut(Self::Item) -> bool
, { ... }
fn any<F>(self, f: F) -> bool
    where
        F: FnMut(Self::Item) -> bool
, { ... }
fn chain<U>(
        self,
        other: U
    ) -> Chain<Self, <U as IntoInternalIterator>::IntoIter>
    where
        U: IntoInternalIterator<Item = Self::Item>
, { ... }
fn cloned<'a, T: 'a>(self) -> Cloned<Self>
    where
        Self: InternalIterator<Item = &'a T>,
        T: Clone
, { ... }
fn collect<B>(self) -> B
    where
        B: FromInternalIterator<Self::Item>
, { ... }
fn copied<'a, T: 'a>(self) -> Copied<Self>
    where
        Self: InternalIterator<Item = &'a T>,
        T: Copy
, { ... }
fn count(self) -> usize { ... }
fn enumerate(self) -> Enumerate<Self> { ... }
fn filter<P>(self, predicate: P) -> Filter<Self, P>
    where
        P: FnMut(&Self::Item) -> bool
, { ... }
fn filter_map<T, F>(self, f: F) -> FilterMap<Self, F>
    where
        F: FnMut(Self::Item) -> Option<T>
, { ... }
fn find<F>(self, f: F) -> Option<Self::Item>
    where
        F: FnMut(&Self::Item) -> bool
, { ... }
fn flat_map<U, F>(self, f: F) -> FlatMap<Self, F>
    where
        F: FnMut(Self::Item) -> U,
        U: IntoInternalIterator
, { ... }
fn for_each<F>(self, f: F)
    where
        F: FnMut(Self::Item)
, { ... }
fn inspect<F>(self, f: F) -> Inspect<Self, F>
    where
        F: FnMut(&Self::Item)
, { ... }
fn last(self) -> Option<Self::Item> { ... }
fn map<F, T>(self, f: F) -> Map<Self, F>
    where
        F: FnMut(Self::Item) -> T
, { ... }
fn max(self) -> Option<Self::Item>
    where
        Self::Item: Ord
, { ... }
fn max_by<F>(self, compare: F) -> Option<Self::Item>
    where
        F: FnMut(&Self::Item, &Self::Item) -> Ordering
, { ... }
fn max_by_key<B: Ord>(
        self,
        key: impl FnMut(&Self::Item) -> B
    ) -> Option<Self::Item> { ... }
fn min(self) -> Option<Self::Item>
    where
        Self::Item: Ord
, { ... }
fn min_by<F>(self, compare: F) -> Option<Self::Item>
    where
        F: FnMut(&Self::Item, &Self::Item) -> Ordering
, { ... }
fn min_by_key<B: Ord>(
        self,
        key: impl FnMut(&Self::Item) -> B
    ) -> Option<Self::Item> { ... }
fn next(self) -> Option<Self::Item> { ... }
fn nth(self, n: usize) -> Option<Self::Item> { ... }
fn position<F>(self, f: F) -> Option<usize>
    where
        F: FnMut(Self::Item) -> bool
, { ... }
fn skip(self, n: usize) -> Skip<Self> { ... }
fn take(self, n: usize) -> Take<Self> { ... }
}
Expand description

Internal iterator over a collection.

Associated Types

Type of items yielded by the iterator.

Required methods

Applies function each elements of the iterator. Stops early if the function returns ControlFlow::Break.

let a = [1, 2, 3, 4, 5, 6];
let mut collected = Vec::new();

let result = a.iter().into_internal().try_for_each(|&x| {
    collected.push(x);
    if x == 4 {
        ControlFlow::Break("stopped!")
    } else {
        ControlFlow::Continue(())
    }
});

assert_eq!(collected, [1, 2, 3, 4]);
assert_eq!(result, ControlFlow::Break("stopped!"));

Provided methods

Applies function to the elements of iterator and returns the first non-none result.

let a = ["lol", "two", "NaN", "4", "5"];

let parsed = a
    .iter()
    .into_internal()
    .find_map(|x| x.parse().ok());

assert_eq!(parsed, Some(4));

Tests if every element of the iterator matches the predicate.

let a = [1, 2, 3];
assert!(a.iter().into_internal().all(|&x| x > 0));
assert!(!a.iter().into_internal().all(|&x| x < 2));

Tests if any element of the iterator matches the predicate.

let a = [1, 2, 3];
assert!(a.iter().into_internal().any(|&x| x == 2));
assert!(!a.iter().into_internal().any(|&x| x > 5));

Takes two iterators and returns an iterator that first iterates over the elements of the first iterator, and then over the second one.

let a1 = [1, 2, 3];
let a2 = [4, 5, 6];

let chained = a1.iter().into_internal()
    .chain(a2.iter().into_internal())
    .collect::<Vec<_>>();

assert_eq!(chained, vec![&1, &2, &3, &4, &5, &6]);

Creates an iterator yields cloned elements of the original iterator.

let a = [1, 2, 3];

let cloned = a.iter().into_internal().cloned().collect::<Vec<_>>();

assert_eq!(cloned, vec![1, 2, 3]);

Transforms the iterator into a collection.

let a = [1, 2, 3];

let doubled = a
    .iter()
    .into_internal()
    .map(|&x| x * 2)
    .collect::<Vec<_>>();

assert_eq!(doubled, vec![2, 4, 6]);

Creates an iterator yields copied elements of the original iterator.

let a = [1, 2, 3];

let cloned = a.iter().into_internal().copied().collect::<Vec<_>>();

assert_eq!(cloned, vec![1, 2, 3]);

Returns the number of elements yielded by the iterator.

let a = [1, 2, 3];

assert_eq!(a.iter().into_internal().count(), 3);

Creates an iterator that adds the index to every value of the original iterator.

let a = ['a', 'b', 'c'];

let enumerated = a.iter().into_internal().enumerate().collect::<Vec<_>>();

assert_eq!(enumerated, vec![(0, &'a'), (1, &'b'), (2, &'c')]);

Creates an iterator which only yields elements matching the predicate.

let a = [0i32, 1, 2];

let positive = a.iter().into_internal().filter(|x| x.is_positive()).collect::<Vec<_>>();

assert_eq!(positive, vec![&1, &2]);

A combination of InternalIterator::filter and InternalIterator::map.

let a = ["1", "two", "NaN", "four", "5"];

let parsed: Vec<_> = a
    .iter()
    .into_internal()
    .filter_map(|x| x.parse::<i32>().ok())
    .collect();

assert_eq!(parsed, vec![1, 5]);

Returns the first element of the iterator that matches the predicate.

let a = [1, 2, 3];

assert_eq!(a.iter().into_internal().find(|&&x| x == 2), Some(&2));

assert_eq!(a.iter().into_internal().find(|&&x| x == 5), None);

Creates and iterator which maps over the elements and flattens the resulting structure.

The provided closure is expected to return a type implementing IntoInternalIterator. The usual types that work with std::iter::Iterator::flat_map don’t work here, so you will need to use IteratorExt::into_internal to use regular iterators with this function.

let a = [1, 2, 3];

let mapped = a.iter()
    .into_internal()
    .flat_map(|&x| [x * 10 + 2, x * 10 + 3])
    .collect::<Vec<_>>();

assert_eq!(mapped, vec![12, 13, 22, 23, 32, 33]);

Run the closure on each element.

Run the closure on each element, while passing that element on.

This can be used to inspect the values passed through the iterator while not modifying the rest of the iterator pipeline.

let a = [1, 4, 6, 3, 2];

let v = a.iter()
    .into_internal()
    .filter(|&x| x % 2 == 0)
    .inspect(|x| println!("item: {}", x))
    .map(|x| x / 2)
    .collect::<Vec<_>>();

assert_eq!(v, vec![2, 3, 1]);
// also prints to stdout:
// item: 4
// item: 6
// item: 2

Returns the last element.

let a = [1, 2, 3];
assert_eq!(a.iter().into_internal().last(), Some(&3));

let a = [1, 2, 3, 4, 5];
assert_eq!(a.iter().into_internal().last(), Some(&5));

Transform each element in the iterator.

let a = [1, 2, 3];

let doubled = a
    .iter()
    .into_internal()
    .map(|&x| x * 2)
    .collect::<Vec<_>>();

assert_eq!(doubled, vec![2, 4, 6]);

Returns the maximum element of an iterator.

let a = [1, 2, 3];
let b: Vec<u32> = Vec::new();

assert_eq!(a.iter().into_internal().max(), Some(&3));
assert_eq!(b.iter().into_internal().max(), None);

Returns the maximum element of an iterator using a custom comparer function.

Returns the element that gives the maximum value from the specified function.

Returns the minimum element of an iterator.

let a = [1, 2, 3];
let b: Vec<u32> = Vec::new();

assert_eq!(a.iter().into_internal().min(), Some(&1));
assert_eq!(b.iter().into_internal().min(), None);

Returns the minimum element of an iterator using a custom comparer function.

Returns the element that gives the minimum value from the specified function.

Returns the first element of the iterator.

Note that unlike Iterator::next, this method consumes the iterator. It is really only useful for getting the first element in the iterator, and is called next just for api similarity with regular iterators.

let a = [1, 2, 3];
assert_eq!(a.iter().into_internal().next(), Some(&1));

Returns the nth element of the iterator.

let a = [1, 2, 3];
assert_eq!(a.iter().into_internal().nth(1), Some(&2));

Returns the index of the first element matching the predicate.

let a = [1, 2, 3];

assert_eq!(a.iter().into_internal().position(|&x| x == 2), Some(1));

assert_eq!(a.iter().into_internal().position(|&x| x == 5), None);

Skip first n elements of the iterator.

let a = [1, 2, 3, 4];

let v = a.iter().into_internal().skip(2).collect::<Vec<_>>();

assert_eq!(v, vec![&3, &4]);

Take first n elements of the iterator, disregarding the rest.

let a = [1, 2, 3, 4];

let v = a.iter().into_internal().take(2).collect::<Vec<_>>();

assert_eq!(v, vec![&1, &2]);

Implementors