1.0.0[][src]Trait tract_onnx::prelude::tract_itertools::__std_iter::ExactSizeIterator

pub trait ExactSizeIterator: Iterator {
    fn len(&self) -> usize { ... }
fn is_empty(&self) -> bool { ... } }

An iterator that knows its exact length.

Many Iterators don't know how many times they will iterate, but some do. If an iterator knows how many times it can iterate, providing access to that information can be useful. For example, if you want to iterate backwards, a good start is to know where the end is.

When implementing an ExactSizeIterator, you must also implement Iterator. When doing so, the implementation of size_hint must return the exact size of the iterator.

The len method has a default implementation, so you usually shouldn't implement it. However, you may be able to provide a more performant implementation than the default, so overriding it in this case makes sense.

Examples

Basic usage:

// a finite range knows exactly how many times it will iterate
let five = 0..5;

assert_eq!(5, five.len());

In the module level docs, we implemented an Iterator, Counter. Let's implement ExactSizeIterator for it as well:

impl ExactSizeIterator for Counter {
    // We can easily calculate the remaining number of iterations.
    fn len(&self) -> usize {
        5 - self.count
    }
}

// And now we can use it!

let counter = Counter::new();

assert_eq!(5, counter.len());

Provided methods

fn len(&self) -> usize

Returns the exact length of the iterator.

The implementation ensures that the iterator will return exactly len() more times a Some(T) value, before returning None. This method has a default implementation, so you usually should not implement it directly. However, if you can provide a more efficient implementation, you can do so. See the trait-level docs for an example.

This function has the same safety guarantees as the size_hint function.

Examples

Basic usage:

// a finite range knows exactly how many times it will iterate
let five = 0..5;

assert_eq!(5, five.len());

fn is_empty(&self) -> bool

🔬 This is a nightly-only experimental API. (exact_size_is_empty)

Returns true if the iterator is empty.

This method has a default implementation using self.len(), so you don't need to implement it yourself.

Examples

Basic usage:

#![feature(exact_size_is_empty)]

let mut one_element = std::iter::once(0);
assert!(!one_element.is_empty());

assert_eq!(one_element.next(), Some(0));
assert!(one_element.is_empty());

assert_eq!(one_element.next(), None);
Loading content...

Implementations on Foreign Types

impl<'_, K, V> ExactSizeIterator for IterMut<'_, K, V>[src]

impl ExactSizeIterator for Args[src]

impl<'_, K, V> ExactSizeIterator for Drain<'_, K, V>[src]

impl<'_, K, V> ExactSizeIterator for Iter<'_, K, V>[src]

impl<'_, K, V> ExactSizeIterator for ValuesMut<'_, K, V>[src]

impl<K> ExactSizeIterator for IntoIter<K>[src]

impl<'_, K> ExactSizeIterator for Drain<'_, K>[src]

impl<K, V> ExactSizeIterator for IntoIter<K, V>[src]

impl<'_, K, V> ExactSizeIterator for Keys<'_, K, V>[src]

impl<K, V> ExactSizeIterator for IntoKeys<K, V>[src]

impl<'_, K, V> ExactSizeIterator for Values<'_, K, V>[src]

impl<K, V> ExactSizeIterator for IntoValues<K, V>[src]

impl<'_, K> ExactSizeIterator for Iter<'_, K>[src]

impl ExactSizeIterator for ArgsOs[src]

impl<'_, T> ExactSizeIterator for ChunksMut<'_, T>[src]

impl ExactSizeIterator for RangeInclusive<i16>[src]

impl ExactSizeIterator for Range<i16>[src]

impl<'_, T> ExactSizeIterator for Iter<'_, T>[src]

impl<'a, T> ExactSizeIterator for RChunksExact<'a, T>[src]

impl ExactSizeIterator for Range<u16>[src]

impl<'_, T> ExactSizeIterator for ChunksExactMut<'_, T>[src]

impl<'_> ExactSizeIterator for Bytes<'_>[src]

impl<T> ExactSizeIterator for IntoIter<T>[src]

impl<'_, T> ExactSizeIterator for IterMut<'_, T>[src]

impl ExactSizeIterator for EscapeDefault[src]

impl ExactSizeIterator for ToLowercase[src]

impl ExactSizeIterator for Range<usize>[src]

impl<'_, I> ExactSizeIterator for &'_ mut I where
    I: ExactSizeIterator + ?Sized
[src]

impl<'_, T, const N: usize> ExactSizeIterator for ArrayChunks<'_, T, N>[src]

impl ExactSizeIterator for Range<u32>[src]

impl ExactSizeIterator for RangeInclusive<i8>[src]

impl<'_, T> ExactSizeIterator for RChunks<'_, T>[src]

impl ExactSizeIterator for ToUppercase[src]

impl ExactSizeIterator for Range<isize>[src]

impl<'_, T> ExactSizeIterator for ChunksExact<'_, T>[src]

impl<'_, T> ExactSizeIterator for RChunksExactMut<'_, T>[src]

impl<'_, T> ExactSizeIterator for Iter<'_, T>[src]

impl<'_, T> ExactSizeIterator for IterMut<'_, T>[src]

impl ExactSizeIterator for Range<i8>[src]

impl ExactSizeIterator for RangeInclusive<u16>[src]

impl<A> ExactSizeIterator for IntoIter<A>[src]

impl ExactSizeIterator for Range<u8>[src]

impl ExactSizeIterator for EscapeUnicode[src]

impl<T, const N: usize> ExactSizeIterator for IntoIter<T, N>[src]

impl<'_, T> ExactSizeIterator for RChunksMut<'_, T>[src]

impl<'_, A> ExactSizeIterator for IterMut<'_, A>[src]

impl<'_, T> ExactSizeIterator for Windows<'_, T>[src]

impl ExactSizeIterator for EscapeDebug[src]

impl ExactSizeIterator for RangeInclusive<u8>[src]

impl<'_, A> ExactSizeIterator for Iter<'_, A>[src]

impl ExactSizeIterator for EscapeDefault[src]

impl ExactSizeIterator for Range<i32>[src]

impl<'_, T> ExactSizeIterator for Chunks<'_, T>[src]

impl<T> ExactSizeIterator for IntoIter<T>[src]

impl<'_, T> ExactSizeIterator for Iter<'_, T>[src]

impl<'_, T> ExactSizeIterator for IterMut<'_, T>[src]

impl<T> ExactSizeIterator for IntoIter<T>[src]

impl<'_, I> ExactSizeIterator for Splice<'_, I> where
    I: Iterator
[src]

impl<'_, K, V> ExactSizeIterator for Values<'_, K, V>[src]

impl<'_, T> ExactSizeIterator for Iter<'_, T>[src]

impl<'_, T> ExactSizeIterator for Drain<'_, T>[src]

impl<T> ExactSizeIterator for IntoIter<T>[src]

impl<I> ExactSizeIterator for Box<I> where
    I: ExactSizeIterator + ?Sized
[src]

impl<'_, K, V> ExactSizeIterator for Iter<'_, K, V>[src]

impl<K, V> ExactSizeIterator for IntoValues<K, V>[src]

impl<'_, T> ExactSizeIterator for Drain<'_, T>[src]

impl<'_, K, V> ExactSizeIterator for Keys<'_, K, V>[src]

impl<'_, T> ExactSizeIterator for Iter<'_, T>[src]

impl<K, V> ExactSizeIterator for IntoKeys<K, V>[src]

impl<'_, T> ExactSizeIterator for IterMut<'_, T>[src]

impl<K, V> ExactSizeIterator for IntoIter<K, V>[src]

impl<'_, T> ExactSizeIterator for DrainSorted<'_, T> where
    T: Ord
[src]

impl<'_, T> ExactSizeIterator for Drain<'_, T>[src]

impl<T> ExactSizeIterator for IntoIterSorted<T> where
    T: Ord
[src]

impl<'_, T> ExactSizeIterator for Iter<'_, T>[src]

impl<T> ExactSizeIterator for IntoIter<T>[src]

impl<'_, K, V> ExactSizeIterator for IterMut<'_, K, V>[src]

impl<T> ExactSizeIterator for IntoIter<T>[src]

impl<'_, K, V> ExactSizeIterator for ValuesMut<'_, K, V>[src]

impl<K> ExactSizeIterator for IntoIter<K>

impl<'_, K, V> ExactSizeIterator for IterMut<'_, K, V>

impl<'_, K, V> ExactSizeIterator for Drain<'_, K, V>

impl<'_, K, V> ExactSizeIterator for ValuesMut<'_, K, V>

impl<'_, K, V> ExactSizeIterator for Iter<'_, K, V>

impl<'a, K> ExactSizeIterator for Iter<'a, K>

impl<'_, K, V> ExactSizeIterator for Keys<'_, K, V>

impl<K, V> ExactSizeIterator for IntoIter<K, V>

impl<'_, K> ExactSizeIterator for Drain<'_, K>

impl<'_, K, V> ExactSizeIterator for Values<'_, K, V>

impl<B> ExactSizeIterator for IntoIter<B> where
    B: BitBlock, 

impl<'a, B> ExactSizeIterator for Blocks<'a, B> where
    B: BitBlock, 

impl<'a, B> ExactSizeIterator for Iter<'a, B> where
    B: BitBlock, 

impl<A> ExactSizeIterator for Zip<(A,)> where
    A: ExactSizeIterator
[src]

impl<I> ExactSizeIterator for Tee<I> where
    I: ExactSizeIterator,
    <I as Iterator>::Item: Clone
[src]

impl<I> ExactSizeIterator for WithPosition<I> where
    I: ExactSizeIterator
[src]

impl<I> ExactSizeIterator for Step<I> where
    I: ExactSizeIterator
[src]

impl<I> ExactSizeIterator for ExactlyOneError<I> where
    I: ExactSizeIterator
[src]

impl<A, B, C, D, E, F> ExactSizeIterator for Zip<(A, B, C, D, E, F)> where
    A: ExactSizeIterator,
    B: ExactSizeIterator,
    C: ExactSizeIterator,
    D: ExactSizeIterator,
    E: ExactSizeIterator,
    F: ExactSizeIterator
[src]

impl<A, B, C, D, E, F, G, H> ExactSizeIterator for Zip<(A, B, C, D, E, F, G, H)> where
    A: ExactSizeIterator,
    B: ExactSizeIterator,
    C: ExactSizeIterator,
    D: ExactSizeIterator,
    E: ExactSizeIterator,
    F: ExactSizeIterator,
    G: ExactSizeIterator,
    H: ExactSizeIterator
[src]

impl<I, F> ExactSizeIterator for PadUsing<I, F> where
    F: FnMut(usize) -> <I as Iterator>::Item,
    I: ExactSizeIterator
[src]

impl<A, B, C, D, E, F, G> ExactSizeIterator for Zip<(A, B, C, D, E, F, G)> where
    A: ExactSizeIterator,
    B: ExactSizeIterator,
    C: ExactSizeIterator,
    D: ExactSizeIterator,
    E: ExactSizeIterator,
    F: ExactSizeIterator,
    G: ExactSizeIterator
[src]

impl<T, U> ExactSizeIterator for ZipLongest<T, U> where
    T: ExactSizeIterator,
    U: ExactSizeIterator
[src]

impl<I, R> ExactSizeIterator for MapInto<I, R> where
    I: ExactSizeIterator,
    <I as Iterator>::Item: Into<R>, 
[src]

impl<A> ExactSizeIterator for RepeatN<A> where
    A: Clone
[src]

impl<A, B, C, D, E> ExactSizeIterator for Zip<(A, B, C, D, E)> where
    A: ExactSizeIterator,
    B: ExactSizeIterator,
    C: ExactSizeIterator,
    D: ExactSizeIterator,
    E: ExactSizeIterator
[src]

impl<A, B, C> ExactSizeIterator for Zip<(A, B, C)> where
    A: ExactSizeIterator,
    B: ExactSizeIterator,
    C: ExactSizeIterator
[src]

impl<I, J> ExactSizeIterator for ZipEq<I, J> where
    I: ExactSizeIterator,
    J: ExactSizeIterator
[src]

impl<A, B, C, D> ExactSizeIterator for Zip<(A, B, C, D)> where
    A: ExactSizeIterator,
    B: ExactSizeIterator,
    C: ExactSizeIterator,
    D: ExactSizeIterator
[src]

impl<T> ExactSizeIterator for TupleBuffer<T> where
    T: TupleCollect, 
[src]

impl<I, F> ExactSizeIterator for Update<I, F> where
    F: FnMut(&mut <I as Iterator>::Item),
    I: ExactSizeIterator
[src]

impl<I> ExactSizeIterator for MultiPeek<I> where
    I: ExactSizeIterator
[src]

impl<A, B> ExactSizeIterator for Zip<(A, B)> where
    A: ExactSizeIterator,
    B: ExactSizeIterator
[src]

impl<A> ExactSizeIterator for IntoIter<A> where
    A: Array
[src]

impl<'a, T> ExactSizeIterator for Drain<'a, T> where
    T: Array
[src]

impl<T> ExactSizeIterator for IntoIter<T> where
    T: Buf
[src]

impl<A> ExactSizeIterator for IntoIter<A> where
    A: Array
[src]

impl<'a, A> ExactSizeIterator for Drain<'a, A> where
    A: Array,
    <A as Array>::Item: 'a, 
[src]

Loading content...

Implementors

impl<'a, A, D> ExactSizeIterator for AxisChunksIter<'a, A, D> where
    D: Dimension
[src]

impl<'a, A, D> ExactSizeIterator for AxisChunksIterMut<'a, A, D> where
    D: Dimension
[src]

impl<'a, A, D> ExactSizeIterator for AxisIter<'a, A, D> where
    D: Dimension
[src]

impl<'a, A, D> ExactSizeIterator for AxisIterMut<'a, A, D> where
    D: Dimension
[src]

impl<'a, A, D> ExactSizeIterator for IndexedIter<'a, A, D> where
    D: Dimension
[src]

impl<'a, A, D> ExactSizeIterator for IndexedIterMut<'a, A, D> where
    D: Dimension
[src]

impl<'a, A, D> ExactSizeIterator for tract_onnx::prelude::tract_ndarray::iter::Iter<'a, A, D> where
    D: Dimension
[src]

impl<'a, A, D> ExactSizeIterator for tract_onnx::prelude::tract_ndarray::iter::IterMut<'a, A, D> where
    D: Dimension
[src]

impl<'a, A, D> ExactSizeIterator for LanesIter<'a, A, D> where
    D: Dimension
[src]

impl<'a, A, D> ExactSizeIterator for LanesIterMut<'a, A, D> where
    D: Dimension
[src]

impl<'a, I, T> ExactSizeIterator for Cloned<I> where
    I: ExactSizeIterator<Item = &'a T>,
    T: 'a + Clone
[src]

impl<'a, I, T> ExactSizeIterator for Copied<I> where
    I: ExactSizeIterator<Item = &'a T>,
    T: 'a + Copy
[src]

impl<A> ExactSizeIterator for tract_onnx::prelude::tract_itertools::RepeatN<A> where
    A: Clone
[src]

impl<A> ExactSizeIterator for tract_onnx::prelude::tract_itertools::Zip<(A,)> where
    A: ExactSizeIterator
[src]

impl<A, B> ExactSizeIterator for tract_onnx::prelude::tract_itertools::__std_iter::Zip<A, B> where
    A: ExactSizeIterator,
    B: ExactSizeIterator
[src]

impl<A, B> ExactSizeIterator for tract_onnx::prelude::tract_itertools::Zip<(A, B)> where
    A: ExactSizeIterator,
    B: ExactSizeIterator
[src]

impl<A, B, C> ExactSizeIterator for tract_onnx::prelude::tract_itertools::Zip<(A, B, C)> where
    A: ExactSizeIterator,
    B: ExactSizeIterator,
    C: ExactSizeIterator
[src]

impl<A, B, C, D> ExactSizeIterator for tract_onnx::prelude::tract_itertools::Zip<(A, B, C, D)> where
    A: ExactSizeIterator,
    B: ExactSizeIterator,
    C: ExactSizeIterator,
    D: ExactSizeIterator
[src]

impl<A, B, C, D, E> ExactSizeIterator for tract_onnx::prelude::tract_itertools::Zip<(A, B, C, D, E)> where
    A: ExactSizeIterator,
    B: ExactSizeIterator,
    C: ExactSizeIterator,
    D: ExactSizeIterator,
    E: ExactSizeIterator
[src]

impl<A, B, C, D, E, F> ExactSizeIterator for tract_onnx::prelude::tract_itertools::Zip<(A, B, C, D, E, F)> where
    A: ExactSizeIterator,
    B: ExactSizeIterator,
    C: ExactSizeIterator,
    D: ExactSizeIterator,
    E: ExactSizeIterator,
    F: ExactSizeIterator
[src]

impl<A, B, C, D, E, F, G> ExactSizeIterator for tract_onnx::prelude::tract_itertools::Zip<(A, B, C, D, E, F, G)> where
    A: ExactSizeIterator,
    B: ExactSizeIterator,
    C: ExactSizeIterator,
    D: ExactSizeIterator,
    E: ExactSizeIterator,
    F: ExactSizeIterator,
    G: ExactSizeIterator
[src]

impl<A, B, C, D, E, F, G, H> ExactSizeIterator for tract_onnx::prelude::tract_itertools::Zip<(A, B, C, D, E, F, G, H)> where
    A: ExactSizeIterator,
    B: ExactSizeIterator,
    C: ExactSizeIterator,
    D: ExactSizeIterator,
    E: ExactSizeIterator,
    F: ExactSizeIterator,
    G: ExactSizeIterator,
    H: ExactSizeIterator
[src]

impl<A, F> ExactSizeIterator for OnceWith<F> where
    F: FnOnce() -> A, 
[src]

impl<B, I, F> ExactSizeIterator for Map<I, F> where
    F: FnMut(<I as Iterator>::Item) -> B,
    I: ExactSizeIterator
[src]

impl<D> ExactSizeIterator for IndicesIter<D> where
    D: Dimension
[src]

impl<I> ExactSizeIterator for Enumerate<I> where
    I: ExactSizeIterator
[src]

impl<I> ExactSizeIterator for Fuse<I> where
    I: ExactSizeIterator
[src]

impl<I> ExactSizeIterator for Peekable<I> where
    I: ExactSizeIterator
[src]

impl<I> ExactSizeIterator for Rev<I> where
    I: ExactSizeIterator + DoubleEndedIterator
[src]

impl<I> ExactSizeIterator for Skip<I> where
    I: ExactSizeIterator
[src]

impl<I> ExactSizeIterator for StepBy<I> where
    I: ExactSizeIterator
[src]

impl<I> ExactSizeIterator for Take<I> where
    I: ExactSizeIterator
[src]

impl<I> ExactSizeIterator for tract_onnx::prelude::tract_itertools::ExactlyOneError<I> where
    I: ExactSizeIterator
[src]

impl<I> ExactSizeIterator for tract_onnx::prelude::tract_itertools::MultiPeek<I> where
    I: ExactSizeIterator
[src]

impl<I> ExactSizeIterator for tract_onnx::prelude::tract_itertools::Step<I> where
    I: ExactSizeIterator
[src]

impl<I> ExactSizeIterator for tract_onnx::prelude::tract_itertools::Tee<I> where
    I: ExactSizeIterator,
    <I as Iterator>::Item: Clone
[src]

impl<I> ExactSizeIterator for tract_onnx::prelude::tract_itertools::WithPosition<I> where
    I: ExactSizeIterator
[src]

impl<I, F> ExactSizeIterator for Inspect<I, F> where
    F: FnMut(&<I as Iterator>::Item),
    I: ExactSizeIterator
[src]

impl<I, F> ExactSizeIterator for tract_onnx::prelude::tract_itertools::PadUsing<I, F> where
    F: FnMut(usize) -> <I as Iterator>::Item,
    I: ExactSizeIterator
[src]

impl<I, F> ExactSizeIterator for tract_onnx::prelude::tract_itertools::Update<I, F> where
    F: FnMut(&mut <I as Iterator>::Item),
    I: ExactSizeIterator
[src]

impl<I, J> ExactSizeIterator for tract_onnx::prelude::tract_itertools::ZipEq<I, J> where
    I: ExactSizeIterator,
    J: ExactSizeIterator
[src]

impl<I, R> ExactSizeIterator for tract_onnx::prelude::tract_itertools::MapInto<I, R> where
    I: ExactSizeIterator,
    <I as Iterator>::Item: Into<R>, 
[src]

impl<L, R> ExactSizeIterator for Either<L, R> where
    L: ExactSizeIterator,
    R: ExactSizeIterator<Item = <L as Iterator>::Item>, 
[src]

impl<T> ExactSizeIterator for Empty<T>[src]

impl<T> ExactSizeIterator for Once<T>[src]

impl<T> ExactSizeIterator for tract_onnx::prelude::tract_itertools::TupleBuffer<T> where
    T: HomogeneousTuple
[src]

impl<T, U> ExactSizeIterator for tract_onnx::prelude::tract_itertools::ZipLongest<T, U> where
    T: ExactSizeIterator,
    U: ExactSizeIterator
[src]

Loading content...