An iterator that knows its exact length.
Many Iterator
s 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.
Basic usage:
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 {
fn len(&self) -> usize {
5 - self.count
}
}
let counter = Counter::new();
assert_eq!(5, counter.len());
Returns the exact number of times the iterator will iterate.
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.
Basic usage:
let five = 0..5;
assert_eq!(5, five.len());
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
Returns whether the iterator is empty.
This method has a default implementation using self.len()
, so you
don't need to implement it yourself.
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...
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
Loading content...
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
impl<'_, A> ExactSizeIterator for boolean_enums::lstd::option::Iter<'_, A> | [src] |
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
impl<'_, A> ExactSizeIterator for boolean_enums::lstd::option::IterMut<'_, A> | [src] |
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
impl<'_, T> ExactSizeIterator for boolean_enums::lstd::result::Iter<'_, T> | [src] |
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
impl<'_, T> ExactSizeIterator for boolean_enums::lstd::result::IterMut<'_, T> | [src] |
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
impl<'a, K> ExactSizeIterator for boolean_enums::lstd::collections::hash_set::Drain<'a, K> | [src] |
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
impl<'a, K> ExactSizeIterator for boolean_enums::lstd::collections::hash_set::Iter<'a, K> | [src] |
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
impl<'a, K, V> ExactSizeIterator for boolean_enums::lstd::collections::hash_map::ValuesMut<'a, K, V> | [src] |
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
impl<'a, K, V> ExactSizeIterator for boolean_enums::lstd::collections::hash_map::Drain<'a, K, V> | [src] |
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
impl<'a, K, V> ExactSizeIterator for boolean_enums::lstd::collections::hash_map::IterMut<'a, K, V> | [src] |
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
impl<'a, K, V> ExactSizeIterator for boolean_enums::lstd::collections::hash_map::Values<'a, K, V> | [src] |
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
impl<'a, K, V> ExactSizeIterator for boolean_enums::lstd::collections::hash_map::Keys<'a, K, V> | [src] |
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
impl<'a, K, V> ExactSizeIterator for boolean_enums::lstd::collections::hash_map::Iter<'a, K, V> | [src] |
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
impl<'a, K, V> ExactSizeIterator for boolean_enums::lstd::collections::btree_map::Keys<'a, K, V> | [src] |
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
impl<'a, K, V> ExactSizeIterator for boolean_enums::lstd::collections::btree_map::ValuesMut<'a, K, V> | [src] |
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
impl<'a, K, V> ExactSizeIterator for boolean_enums::lstd::collections::btree_map::Iter<'a, K, V> where K: 'a, V: 'a, | [src] |
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
impl<'a, K, V> ExactSizeIterator for boolean_enums::lstd::collections::btree_map::Values<'a, K, V> | [src] |
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
impl<'a, K, V> ExactSizeIterator for boolean_enums::lstd::collections::btree_map::IterMut<'a, K, V> where K: 'a, V: 'a, | [src] |
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
impl<'a, T> ExactSizeIterator for boolean_enums::lstd::slice::IterMut<'a, T> | [src] |
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
impl<'a, T> ExactSizeIterator for boolean_enums::lstd::slice::Iter<'a, T> | [src] |
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
impl<'a, T> ExactSizeIterator for boolean_enums::lstd::collections::binary_heap::Drain<'a, T> where T: 'a, | [src] |
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
impl<'a, T> ExactSizeIterator for boolean_enums::lstd::collections::vec_deque::Drain<'a, T> where T: 'a, | [src] |
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
impl<'a, T> ExactSizeIterator for boolean_enums::lstd::collections::linked_list::IterMut<'a, T> | [src] |
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
impl<'a, T> ExactSizeIterator for boolean_enums::lstd::collections::binary_heap::Iter<'a, T> | [src] |
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
impl<'a, T> ExactSizeIterator for boolean_enums::lstd::collections::btree_set::Iter<'a, T> | [src] |
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
impl<'a, T> ExactSizeIterator for boolean_enums::lstd::vec::Drain<'a, T> | [src] |
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
impl<'a, T> ExactSizeIterator for boolean_enums::lstd::collections::vec_deque::IterMut<'a, T> | [src] |
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
impl<'a, T> ExactSizeIterator for boolean_enums::lstd::collections::vec_deque::Iter<'a, T> | [src] |
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
impl<'a, T> ExactSizeIterator for boolean_enums::lstd::collections::linked_list::Iter<'a, T> | [src] |
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
impl<A> ExactSizeIterator for boolean_enums::lstd::option::IntoIter<A> | [src] |
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
impl<K> ExactSizeIterator for boolean_enums::lstd::collections::hash_set::IntoIter<K> | [src] |
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
impl<K, V> ExactSizeIterator for boolean_enums::lstd::collections::hash_map::IntoIter<K, V> | [src] |
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
impl<K, V> ExactSizeIterator for boolean_enums::lstd::collections::btree_map::IntoIter<K, V> | [src] |
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
impl<T> ExactSizeIterator for boolean_enums::lstd::result::IntoIter<T> | [src] |
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
impl<T> ExactSizeIterator for boolean_enums::lstd::vec::IntoIter<T> | [src] |
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
impl<T> ExactSizeIterator for boolean_enums::lstd::collections::binary_heap::IntoIter<T> | [src] |
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
impl<T> ExactSizeIterator for boolean_enums::lstd::collections::vec_deque::IntoIter<T> | [src] |
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
impl<T> ExactSizeIterator for boolean_enums::lstd::collections::btree_set::IntoIter<T> | [src] |
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
impl<T> ExactSizeIterator for boolean_enums::lstd::collections::linked_list::IntoIter<T> | [src] |
🔬 This is a nightly-only experimental API. (exact_size_is_empty
)
Loading content...