pub trait InternalIterator: Sized {
    type Item;

Show 30 methods // Required method fn try_for_each<R, F>(self, f: F) -> ControlFlow<R> where F: FnMut(Self::Item) -> ControlFlow<R>; // Provided methods 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>(self) -> Cloned<Self> where Self: InternalIterator<Item = &'a T>, T: Clone + 'a { ... } fn collect<B>(self) -> B where B: FromInternalIterator<Self::Item> { ... } fn copied<'a, T>(self) -> Copied<Self> where Self: InternalIterator<Item = &'a T>, T: Copy + 'a { ... } 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 fold<B, F>(self, init: B, f: F) -> B where F: FnMut(B, Self::Item) -> B { ... } 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.

Required Associated Types§

source

type Item

Type of items yielded by the iterator.

Required Methods§

source

fn try_for_each<R, F>(self, f: F) -> ControlFlow<R>where F: FnMut(Self::Item) -> ControlFlow<R>,

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§

source

fn find_map<R, F>(self, f: F) -> Option<R>where F: FnMut(Self::Item) -> Option<R>,

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));
source

fn all<F>(self, f: F) -> boolwhere F: FnMut(Self::Item) -> bool,

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));
source

fn any<F>(self, f: F) -> boolwhere F: FnMut(Self::Item) -> bool,

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));
source

fn chain<U>( self, other: U ) -> Chain<Self, <U as IntoInternalIterator>::IntoIter>where U: IntoInternalIterator<Item = Self::Item>,

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]);
source

fn cloned<'a, T>(self) -> Cloned<Self>where Self: InternalIterator<Item = &'a T>, T: Clone + 'a,

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]);
source

fn collect<B>(self) -> Bwhere B: FromInternalIterator<Self::Item>,

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]);
source

fn copied<'a, T>(self) -> Copied<Self>where Self: InternalIterator<Item = &'a T>, T: Copy + 'a,

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]);
source

fn count(self) -> usize

Returns the number of elements yielded by the iterator.

let a = [1, 2, 3];

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

fn enumerate(self) -> Enumerate<Self>

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')]);
source

fn filter<P>(self, predicate: P) -> Filter<Self, P>where P: FnMut(&Self::Item) -> bool,

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]);
source

fn filter_map<T, F>(self, f: F) -> FilterMap<Self, F>where F: FnMut(Self::Item) -> Option<T>,

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]);
source

fn find<F>(self, f: F) -> Option<Self::Item>where F: FnMut(&Self::Item) -> bool,

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);
source

fn flat_map<U, F>(self, f: F) -> FlatMap<Self, F>where F: FnMut(Self::Item) -> U, U: IntoInternalIterator,

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]);
source

fn fold<B, F>(self, init: B, f: F) -> Bwhere F: FnMut(B, Self::Item) -> B,

Folds every element into an accumulator by applying an operation, returning the final result.

let a = [1, 2, 3];
let sum = a.into_internal_iter().fold(0, |acc, x| acc + x);
assert_eq!(sum, 6);
source

fn for_each<F>(self, f: F)where F: FnMut(Self::Item),

Run the closure on each element.

source

fn inspect<F>(self, f: F) -> Inspect<Self, F>where F: FnMut(&Self::Item),

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
source

fn last(self) -> Option<Self::Item>

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));
source

fn map<F, T>(self, f: F) -> Map<Self, F>where F: FnMut(Self::Item) -> T,

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]);
source

fn max(self) -> Option<Self::Item>where Self::Item: Ord,

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);
source

fn max_by<F>(self, compare: F) -> Option<Self::Item>where F: FnMut(&Self::Item, &Self::Item) -> Ordering,

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

source

fn max_by_key<B: Ord>( self, key: impl FnMut(&Self::Item) -> B ) -> Option<Self::Item>

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

source

fn min(self) -> Option<Self::Item>where Self::Item: Ord,

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);
source

fn min_by<F>(self, compare: F) -> Option<Self::Item>where F: FnMut(&Self::Item, &Self::Item) -> Ordering,

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

source

fn min_by_key<B: Ord>( self, key: impl FnMut(&Self::Item) -> B ) -> Option<Self::Item>

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

source

fn next(self) -> Option<Self::Item>

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));
source

fn nth(self, n: usize) -> Option<Self::Item>

Returns the nth element of the iterator.

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

fn position<F>(self, f: F) -> Option<usize>where F: FnMut(Self::Item) -> bool,

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);
source

fn skip(self, n: usize) -> Skip<Self>

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]);
source

fn take(self, n: usize) -> Take<Self>

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§

source§

impl<'a, I, T> InternalIterator for Cloned<I>where I: InternalIterator<Item = &'a T>, T: Clone + 'a,

§

type Item = T

source§

impl<'a, I, T> InternalIterator for Copied<I>where I: InternalIterator<Item = &'a T>, T: Copy + 'a,

§

type Item = T

source§

impl<A, B> InternalIterator for Chain<A, B>where A: InternalIterator, B: InternalIterator<Item = A::Item>,

source§

impl<F, R> InternalIterator for FromFn<F, R>where F: for<'a> FnOnce(&mut dyn FnMut(R) -> ControlFlow<BreakValue<'a>>) -> ControlFlow<BreakValue<'a>>,

§

type Item = R

source§

impl<I> InternalIterator for Enumerate<I>where I: InternalIterator,

§

type Item = (usize, <I as InternalIterator>::Item)

source§

impl<I> InternalIterator for Internal<I>where I: Iterator,

§

type Item = <I as Iterator>::Item

source§

impl<I> InternalIterator for Skip<I>where I: InternalIterator,

source§

impl<I> InternalIterator for Take<I>where I: InternalIterator,

source§

impl<I, F> InternalIterator for Filter<I, F>where I: InternalIterator, F: FnMut(&I::Item) -> bool,

source§

impl<I, F> InternalIterator for Inspect<I, F>where I: InternalIterator, F: FnMut(&I::Item),

source§

impl<I, F, T> InternalIterator for FilterMap<I, F>where I: InternalIterator, F: FnMut(I::Item) -> Option<T>,

§

type Item = T

source§

impl<I, F, T> InternalIterator for Map<I, F>where I: InternalIterator, F: FnMut(I::Item) -> T,

§

type Item = T

source§

impl<I, F, T, U> InternalIterator for FlatMap<I, F>where I: InternalIterator, F: FnMut(I::Item) -> U, U: IntoInternalIterator<Item = T>,

§

type Item = T