Trait gat_std::iter::Iterator

source ·
pub trait Iterator {
    type Item<'a>
    where
        Self: 'a
;
Show 22 methods fn next(&mut self) -> Option<Self::Item<'_>>; fn size_hint(&self) -> (usize, Option<usize>) { ... } fn advance_by(&mut self, n: usize) -> Result<(), usize> { ... } fn nth(&mut self, n: usize) -> Option<Self::Item<'_>> { ... } fn map<O, F>(self, f: F) -> Map<Self, F>
    where
        Self: Sized,
        F: FnMut(Self::Item<'_>) -> O
, { ... } fn touch<F>(self, f: F) -> Touch<Self, F>
    where
        Self: Sized,
        F: FnMut(&mut Self::Item<'_>)
, { ... } fn filter<F>(self, f: F) -> Filter<Self, F>
    where
        Self: Sized,
        F: FnMut(&Self::Item<'_>) -> bool
, { ... } fn step_by(self, step: usize) -> StepBy<Self>
    where
        Self: Sized
, { ... } fn chain<U>(self, other: U) -> Chain<Self, U::IntoIter>
    where
        Self: Sized,
        U: IntoIterator,
        U::IntoIter: for<'a> Iterator<Item<'a> = Self::Item<'a>>
, { ... } fn zip<U>(self, other: U) -> Zip<Self, U::IntoIter>
    where
        Self: Sized,
        U: IntoIterator
, { ... } fn enumerate(self) -> Enumerate<Self>
    where
        Self: Sized
, { ... } fn skip_while<F>(self, f: F) -> SkipWhile<Self, F>
    where
        Self: Sized,
        F: FnMut(&Self::Item<'_>) -> bool
, { ... } fn take_while<F>(self, f: F) -> TakeWhile<Self, F>
    where
        Self: Sized,
        F: FnMut(&Self::Item<'_>) -> bool
, { ... } fn skip(self, n: usize) -> Skip<Self>
    where
        Self: Sized
, { ... } fn take(self, n: usize) -> Take<Self>
    where
        Self: Sized
, { ... } fn all<F>(&mut self, f: F) -> bool
    where
        F: FnMut(Self::Item<'_>) -> bool
, { ... } fn any<F>(&mut self, f: F) -> bool
    where
        F: FnMut(Self::Item<'_>) -> bool
, { ... } fn find<F>(&mut self, f: F) -> Option<Self::Item<'_>>
    where
        F: FnMut(&Self::Item<'_>) -> bool
, { ... } fn count(self) -> usize
    where
        Self: Sized
, { ... } fn for_each<F>(self, f: F)
    where
        Self: Sized,
        F: FnMut(Self::Item<'_>)
, { ... } fn fold<T, F>(self, acc: T, f: F) -> T
    where
        Self: Sized,
        F: FnMut(T, Self::Item<'_>) -> T
, { ... } fn scan<T, B, F>(self, acc: T, f: F) -> Scan<Self, T, F>
    where
        Self: Sized,
        F: FnMut(&mut T, Self::Item<'_>) -> Option<B>
, { ... }
}
Expand description

A lending iterator, whose items may have their lifetimes tied to the individual borrow of the iterator. This allows for things like yielding mutable references that overlap, with the trade-off that there’s no generic collect interface - the items of this iterator cannot co-exist.

Required Associated Types§

The value yielded by each call to next on this iterator

Required Methods§

Get the next value of this iterator, or return None

Provided Methods§

Get a hint as to the size of this iterator - the first value is a lower bound, second is an optional upper bound.

Advance the iterator by n elements

Return the nth element of the iterator

This does not rewind the iterator after completion, so repeatedly calling nth(0) is equivalent to calling next

Take a closure which will take each value from the iterator, and yield a new value computed from it.

The result cannot reference the provided data, as such, this returns an iterator which also implements the non-lending core iterator

Gain mutable access to each value in this iterator, then yield it to the next step. This allows altering each item without consuming it, preserving the lending nature or the iterator

Examples found in repository?
examples/iter.rs (lines 30-32)
27
28
29
30
31
32
33
34
fn main() {
    let iter: Custom = Custom::new();

    iter.touch(|val| {
        **val += 1;
    })
    .for_each(|val| println!("{}", *val));
}

Execute a closure on each item in the iterator, returning true if it should be included, or false to skip it

Creates an iterator starting at the same point, but stepping by the given amount at each iteration

Takes two iterators and creates a new iterator over both in sequence

‘Zips up’ two iterators into a single iterator of pairs

Creates an iterator which gives the current iteration count as well as the next value

Creates an iterator that skips elements based on a predicate

Creates an iterator that yields elements based on a predicate

Creates an iterator that skips the first n elements

Creates an iterator that yields the first n elements, or fewer if the underlying iterator ends sooner

Tests if every element of the iterator matches a predicate

Tests if any element of the iterator matches a predicate

Searches for an element of an iterator that satisfies a predicate

Consume the iterator, counting the number of items and returning it

Execute a closure on each value of this iterator

Examples found in repository?
examples/iter.rs (line 33)
27
28
29
30
31
32
33
34
fn main() {
    let iter: Custom = Custom::new();

    iter.touch(|val| {
        **val += 1;
    })
    .for_each(|val| println!("{}", *val));
}

Execute a closure on each value of this iterator, with an additional ‘accumulator’ value passed to each call. The closure is expected to return the new value of the accumulator.

Execute a closure on each value of this iterator, with an additional state value passed via mutable reference to each call. The closure is expected to return the new value for each step of the iterator, if the returned value is None the iterator stops early.

The result cannot reference the provided data, as such, this returns an iterator which also implements the non-lending core iterator

Implementors§