Trait rocket::mtls::oid::asn1_rs::nom::lib::std::iter::ExactSizeIterator

1.0.0 · source ·
pub trait ExactSizeIterator: Iterator {
    // Provided methods
    fn len(&self) -> usize { ... }
    fn is_empty(&self) -> bool { ... }
}
Available on crate feature mtls only.
Expand description

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 Iterator::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.

Note that this trait is a safe trait and as such does not and cannot guarantee that the returned length is correct. This means that unsafe code must not rely on the correctness of Iterator::size_hint. The unstable and unsafe TrustedLen trait gives this additional guarantee.

§When shouldn’t an adapter be ExactSizeIterator?

If an adapter makes an iterator longer, then it’s usually incorrect for that adapter to implement ExactSizeIterator. The inner exact-sized iterator might already be usize::MAX-long, and thus the length of the longer adapted iterator would no longer be exactly representable in usize.

This is why Chain<A, B> isn’t ExactSizeIterator, even when A and B are both ExactSizeIterator.

§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 mut counter = Counter::new();

assert_eq!(5, counter.len());
let _ = counter.next();
assert_eq!(4, counter.len());

Provided Methods§

source

fn len(&self) -> usize

Returns the exact remaining 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 Iterator::size_hint function.

§Examples

Basic usage:

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

assert_eq!(5, range.len());
let _ = range.next();
assert_eq!(4, range.len());
source

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 ExactSizeIterator::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);

Implementors§

source§

impl ExactSizeIterator for IndexVecIntoIter

source§

impl ExactSizeIterator for U32Digits<'_>

source§

impl ExactSizeIterator for U64Digits<'_>

source§

impl ExactSizeIterator for Range<i8>

source§

impl ExactSizeIterator for Range<i16>

source§

impl ExactSizeIterator for Range<i32>

source§

impl ExactSizeIterator for Range<isize>

source§

impl ExactSizeIterator for Range<u8>

source§

impl ExactSizeIterator for Range<u16>

source§

impl ExactSizeIterator for Range<u32>

source§

impl ExactSizeIterator for Range<usize>

1.26.0 · source§

impl ExactSizeIterator for RangeInclusive<i8>

1.26.0 · source§

impl ExactSizeIterator for RangeInclusive<i16>

1.26.0 · source§

impl ExactSizeIterator for RangeInclusive<u8>

1.26.0 · source§

impl ExactSizeIterator for RangeInclusive<u16>

source§

impl ExactSizeIterator for Bytes<'_>

source§

impl ExactSizeIterator for core::ascii::EscapeDefault

1.20.0 · source§

impl ExactSizeIterator for EscapeDebug

1.11.0 · source§

impl ExactSizeIterator for core::char::EscapeDefault

1.11.0 · source§

impl ExactSizeIterator for EscapeUnicode

1.35.0 · source§

impl ExactSizeIterator for ToLowercase

1.35.0 · source§

impl ExactSizeIterator for ToUppercase

source§

impl ExactSizeIterator for Args

source§

impl ExactSizeIterator for ArgsOs

source§

impl ExactSizeIterator for serde_json::map::IntoIter

§

impl ExactSizeIterator for IntoIter

source§

impl<'a> ExactSizeIterator for IndexVecIter<'a>

1.57.0 · source§

impl<'a> ExactSizeIterator for CommandArgs<'a>

1.57.0 · source§

impl<'a> ExactSizeIterator for CommandEnvs<'a>

source§

impl<'a> ExactSizeIterator for serde_json::map::Iter<'a>

source§

impl<'a> ExactSizeIterator for serde_json::map::IterMut<'a>

source§

impl<'a> ExactSizeIterator for serde_json::map::Keys<'a>

source§

impl<'a> ExactSizeIterator for serde_json::map::Values<'a>

source§

impl<'a> ExactSizeIterator for serde_json::map::ValuesMut<'a>

§

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

§

impl<'a> ExactSizeIterator for IterMut<'a>

§

impl<'a> ExactSizeIterator for Keys<'a>

§

impl<'a> ExactSizeIterator for Values<'a>

1.1.0 · source§

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

1.36.0 · source§

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

§

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

source§

impl<'a, S, T> ExactSizeIterator for SliceChooseIter<'a, S, T>
where S: Index<usize, Output = T> + 'a + ?Sized, T: 'a,

1.31.0 · source§

impl<'a, T> ExactSizeIterator for RChunksExact<'a, T>

source§

impl<'a, T> ExactSizeIterator for http::header::map::Keys<'a, T>

§

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

source§

impl<A> ExactSizeIterator for rocket::mtls::oid::asn1_rs::nom::lib::std::option::IntoIter<A>

source§

impl<A> ExactSizeIterator for rocket::mtls::oid::asn1_rs::nom::lib::std::option::Iter<'_, A>

source§

impl<A> ExactSizeIterator for rocket::mtls::oid::asn1_rs::nom::lib::std::option::IterMut<'_, A>

source§

impl<A> ExactSizeIterator for RepeatN<A>
where A: Clone,

§

impl<A> ExactSizeIterator for IntoIter<A>
where A: Array,

source§

impl<A, B> ExactSizeIterator for Zip<A, B>

1.43.0 · source§

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

source§

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

§

impl<Fut> ExactSizeIterator for IntoIter<Fut>
where Fut: Unpin,

§

impl<Fut> ExactSizeIterator for Iter<'_, Fut>
where Fut: Unpin,

§

impl<Fut> ExactSizeIterator for IterMut<'_, Fut>
where Fut: Unpin,

§

impl<Fut> ExactSizeIterator for IterPinMut<'_, Fut>

§

impl<Fut> ExactSizeIterator for IterPinRef<'_, Fut>

source§

impl<I> ExactSizeIterator for &mut I

source§

impl<I> ExactSizeIterator for Enumerate<I>

source§

impl<I> ExactSizeIterator for Fuse<I>

source§

impl<I> ExactSizeIterator for Peekable<I>

source§

impl<I> ExactSizeIterator for Rev<I>

source§

impl<I> ExactSizeIterator for Skip<I>

1.28.0 · source§

impl<I> ExactSizeIterator for StepBy<I>

source§

impl<I> ExactSizeIterator for Take<I>

source§

impl<I, A> ExactSizeIterator for rocket::mtls::oid::asn1_rs::nom::lib::std::boxed::Box<I, A>

1.21.0 · source§

impl<I, A> ExactSizeIterator for rocket::mtls::oid::asn1_rs::nom::lib::std::vec::Splice<'_, I, A>
where I: Iterator, A: Allocator,

§

impl<I, A> ExactSizeIterator for Box<I, A>
where I: ExactSizeIterator + ?Sized, A: Allocator,

§

impl<I, A> ExactSizeIterator for Splice<'_, I, A>
where I: Iterator, A: Allocator,

source§

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

source§

impl<I, F, R, const N: usize> ExactSizeIterator for MapWindows<I, F, N>
where I: ExactSizeIterator, F: FnMut(&[<I as Iterator>::Item; N]) -> R,

source§

impl<I, K, V, S> ExactSizeIterator for indexmap::map::iter::Splice<'_, I, K, V, S>
where I: Iterator<Item = (K, V)>, K: Hash + Eq, S: BuildHasher,

source§

impl<I, T, S> ExactSizeIterator for indexmap::set::iter::Splice<'_, I, T, S>
where I: Iterator<Item = T>, T: Hash + Eq, S: BuildHasher,

source§

impl<I, const N: usize> ExactSizeIterator for rocket::mtls::oid::asn1_rs::nom::lib::std::iter::ArrayChunks<I, N>

source§

impl<K> ExactSizeIterator for rocket::mtls::oid::asn1_rs::nom::lib::std::collections::hash_set::Drain<'_, K>

source§

impl<K> ExactSizeIterator for rocket::mtls::oid::asn1_rs::nom::lib::std::collections::hash_set::IntoIter<K>

source§

impl<K> ExactSizeIterator for rocket::mtls::oid::asn1_rs::nom::lib::std::collections::hash_set::Iter<'_, K>

§

impl<K, A> ExactSizeIterator for Drain<'_, K, A>
where A: Allocator,

§

impl<K, A> ExactSizeIterator for IntoIter<K, A>
where A: Allocator,

source§

impl<K, V> ExactSizeIterator for rocket::mtls::oid::asn1_rs::nom::lib::std::collections::btree_map::Iter<'_, K, V>

source§

impl<K, V> ExactSizeIterator for rocket::mtls::oid::asn1_rs::nom::lib::std::collections::btree_map::IterMut<'_, K, V>

source§

impl<K, V> ExactSizeIterator for rocket::mtls::oid::asn1_rs::nom::lib::std::collections::btree_map::Keys<'_, K, V>

source§

impl<K, V> ExactSizeIterator for rocket::mtls::oid::asn1_rs::nom::lib::std::collections::btree_map::Values<'_, K, V>

1.10.0 · source§

impl<K, V> ExactSizeIterator for rocket::mtls::oid::asn1_rs::nom::lib::std::collections::btree_map::ValuesMut<'_, K, V>

1.6.0 · source§

impl<K, V> ExactSizeIterator for rocket::mtls::oid::asn1_rs::nom::lib::std::collections::hash_map::Drain<'_, K, V>

source§

impl<K, V> ExactSizeIterator for rocket::mtls::oid::asn1_rs::nom::lib::std::collections::hash_map::IntoIter<K, V>

1.54.0 · source§

impl<K, V> ExactSizeIterator for rocket::mtls::oid::asn1_rs::nom::lib::std::collections::hash_map::IntoKeys<K, V>

1.54.0 · source§

impl<K, V> ExactSizeIterator for rocket::mtls::oid::asn1_rs::nom::lib::std::collections::hash_map::IntoValues<K, V>

source§

impl<K, V> ExactSizeIterator for rocket::mtls::oid::asn1_rs::nom::lib::std::collections::hash_map::Iter<'_, K, V>

source§

impl<K, V> ExactSizeIterator for rocket::mtls::oid::asn1_rs::nom::lib::std::collections::hash_map::IterMut<'_, K, V>

source§

impl<K, V> ExactSizeIterator for rocket::mtls::oid::asn1_rs::nom::lib::std::collections::hash_map::Keys<'_, K, V>

source§

impl<K, V> ExactSizeIterator for rocket::mtls::oid::asn1_rs::nom::lib::std::collections::hash_map::Values<'_, K, V>

1.10.0 · source§

impl<K, V> ExactSizeIterator for rocket::mtls::oid::asn1_rs::nom::lib::std::collections::hash_map::ValuesMut<'_, K, V>

source§

impl<K, V> ExactSizeIterator for indexmap::map::iter::Drain<'_, K, V>

source§

impl<K, V> ExactSizeIterator for indexmap::map::iter::IntoIter<K, V>

source§

impl<K, V> ExactSizeIterator for indexmap::map::iter::IntoKeys<K, V>

source§

impl<K, V> ExactSizeIterator for indexmap::map::iter::IntoValues<K, V>

source§

impl<K, V> ExactSizeIterator for indexmap::map::iter::Iter<'_, K, V>

source§

impl<K, V> ExactSizeIterator for indexmap::map::iter::IterMut<'_, K, V>

source§

impl<K, V> ExactSizeIterator for indexmap::map::iter::Keys<'_, K, V>

source§

impl<K, V> ExactSizeIterator for indexmap::map::iter::Values<'_, K, V>

source§

impl<K, V> ExactSizeIterator for indexmap::map::iter::ValuesMut<'_, K, V>

§

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

§

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

§

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

§

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

§

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

source§

impl<K, V, A> ExactSizeIterator for rocket::mtls::oid::asn1_rs::nom::lib::std::collections::btree_map::IntoIter<K, V, A>
where A: Allocator + Clone,

1.54.0 · source§

impl<K, V, A> ExactSizeIterator for rocket::mtls::oid::asn1_rs::nom::lib::std::collections::btree_map::IntoKeys<K, V, A>
where A: Allocator + Clone,

1.54.0 · source§

impl<K, V, A> ExactSizeIterator for rocket::mtls::oid::asn1_rs::nom::lib::std::collections::btree_map::IntoValues<K, V, A>
where A: Allocator + Clone,

§

impl<K, V, A> ExactSizeIterator for Drain<'_, K, V, A>
where A: Allocator,

§

impl<K, V, A> ExactSizeIterator for IntoIter<K, V, A>
where A: Allocator,

§

impl<K, V, A> ExactSizeIterator for IntoKeys<K, V, A>
where A: Allocator,

§

impl<K, V, A> ExactSizeIterator for IntoValues<K, V, A>
where A: Allocator,

source§

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

source§

impl<L, R> ExactSizeIterator for IterEither<L, R>

§

impl<St> ExactSizeIterator for IntoIter<St>
where St: Stream + Unpin,

§

impl<St> ExactSizeIterator for Iter<'_, St>
where St: Stream + Unpin,

§

impl<St> ExactSizeIterator for IterMut<'_, St>
where St: Stream + Unpin,

source§

impl<T> ExactSizeIterator for rocket::mtls::oid::asn1_rs::nom::lib::std::collections::binary_heap::Iter<'_, T>

source§

impl<T> ExactSizeIterator for rocket::mtls::oid::asn1_rs::nom::lib::std::collections::btree_set::Iter<'_, T>

source§

impl<T> ExactSizeIterator for rocket::mtls::oid::asn1_rs::nom::lib::std::collections::linked_list::Iter<'_, T>

source§

impl<T> ExactSizeIterator for rocket::mtls::oid::asn1_rs::nom::lib::std::collections::linked_list::IterMut<'_, T>

source§

impl<T> ExactSizeIterator for rocket::mtls::oid::asn1_rs::nom::lib::std::collections::vec_deque::Iter<'_, T>

source§

impl<T> ExactSizeIterator for rocket::mtls::oid::asn1_rs::nom::lib::std::collections::vec_deque::IterMut<'_, T>

source§

impl<T> ExactSizeIterator for rocket::mtls::oid::asn1_rs::nom::lib::std::result::IntoIter<T>

source§

impl<T> ExactSizeIterator for rocket::mtls::oid::asn1_rs::nom::lib::std::result::Iter<'_, T>

source§

impl<T> ExactSizeIterator for rocket::mtls::oid::asn1_rs::nom::lib::std::result::IterMut<'_, T>

source§

impl<T> ExactSizeIterator for Chunks<'_, T>

1.31.0 · source§

impl<T> ExactSizeIterator for ChunksExact<'_, T>

1.31.0 · source§

impl<T> ExactSizeIterator for ChunksExactMut<'_, T>

source§

impl<T> ExactSizeIterator for ChunksMut<'_, T>

source§

impl<T> ExactSizeIterator for rocket::mtls::oid::asn1_rs::nom::lib::std::slice::Iter<'_, T>

source§

impl<T> ExactSizeIterator for rocket::mtls::oid::asn1_rs::nom::lib::std::slice::IterMut<'_, T>

1.31.0 · source§

impl<T> ExactSizeIterator for RChunks<'_, T>

1.31.0 · source§

impl<T> ExactSizeIterator for RChunksExactMut<'_, T>

1.31.0 · source§

impl<T> ExactSizeIterator for RChunksMut<'_, T>

source§

impl<T> ExactSizeIterator for Windows<'_, T>

source§

impl<T> ExactSizeIterator for bytes::buf::iter::IntoIter<T>
where T: Buf,

source§

impl<T> ExactSizeIterator for indexmap::set::iter::Drain<'_, T>

source§

impl<T> ExactSizeIterator for indexmap::set::iter::IntoIter<T>

source§

impl<T> ExactSizeIterator for indexmap::set::iter::Iter<'_, T>

source§

impl<T> ExactSizeIterator for PermitIterator<'_, T>

1.2.0 · source§

impl<T> ExactSizeIterator for Empty<T>

1.2.0 · source§

impl<T> ExactSizeIterator for Once<T>

§

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

§

impl<T> ExactSizeIterator for IntoIter<T>

§

impl<T> ExactSizeIterator for Iter<'_, T>

§

impl<T> ExactSizeIterator for Iter<'_, T>

§

impl<T> ExactSizeIterator for IterMut<'_, T>

§

impl<T> ExactSizeIterator for IterMut<'_, T>

§

impl<T> ExactSizeIterator for RawIter<T>

1.6.0 · source§

impl<T, A> ExactSizeIterator for rocket::mtls::oid::asn1_rs::nom::lib::std::collections::binary_heap::Drain<'_, T, A>
where A: Allocator,

source§

impl<T, A> ExactSizeIterator for DrainSorted<'_, T, A>
where T: Ord, A: Allocator,

source§

impl<T, A> ExactSizeIterator for rocket::mtls::oid::asn1_rs::nom::lib::std::collections::binary_heap::IntoIter<T, A>
where A: Allocator,

source§

impl<T, A> ExactSizeIterator for IntoIterSorted<T, A>
where T: Ord, A: Allocator,

source§

impl<T, A> ExactSizeIterator for rocket::mtls::oid::asn1_rs::nom::lib::std::collections::btree_set::IntoIter<T, A>
where A: Allocator + Clone,

source§

impl<T, A> ExactSizeIterator for rocket::mtls::oid::asn1_rs::nom::lib::std::collections::linked_list::IntoIter<T, A>
where A: Allocator,

1.6.0 · source§

impl<T, A> ExactSizeIterator for rocket::mtls::oid::asn1_rs::nom::lib::std::collections::vec_deque::Drain<'_, T, A>
where A: Allocator,

source§

impl<T, A> ExactSizeIterator for rocket::mtls::oid::asn1_rs::nom::lib::std::collections::vec_deque::IntoIter<T, A>
where A: Allocator,

1.6.0 · source§

impl<T, A> ExactSizeIterator for rocket::mtls::oid::asn1_rs::nom::lib::std::vec::Drain<'_, T, A>
where A: Allocator,

source§

impl<T, A> ExactSizeIterator for rocket::mtls::oid::asn1_rs::nom::lib::std::vec::IntoIter<T, A>
where A: Allocator,

§

impl<T, A> ExactSizeIterator for Drain<'_, T, A>
where A: Allocator,

§

impl<T, A> ExactSizeIterator for Drain<'_, T, A>
where A: Allocator,

§

impl<T, A> ExactSizeIterator for IntoIter<T, A>
where A: Allocator,

§

impl<T, A> ExactSizeIterator for IntoIter<T, A>
where A: Allocator,

§

impl<T, A> ExactSizeIterator for RawDrain<'_, T, A>
where A: Allocator,

§

impl<T, A> ExactSizeIterator for RawIntoIter<T, A>
where A: Allocator,

§

impl<T, N> ExactSizeIterator for GenericArrayIter<T, N>
where N: ArrayLength<T>,

source§

impl<T, const N: usize> ExactSizeIterator for rocket::mtls::oid::asn1_rs::nom::lib::std::slice::ArrayChunks<'_, T, N>

source§

impl<T, const N: usize> ExactSizeIterator for ArrayChunksMut<'_, T, N>

source§

impl<T, const N: usize> ExactSizeIterator for ArrayWindows<'_, T, N>

1.40.0 · source§

impl<T, const N: usize> ExactSizeIterator for core::array::iter::IntoIter<T, N>