Function step_count

Source
pub fn step_count<T: Step + Default>(iter: impl IntoIterator) -> T
Expand description

Consumes the iterator, counting the number of iterations. This uses the Step trait to keep track of the count of iterations. The count starts from the default value provided by the Default trait.

Note: This function takes any implementation of IntoIterator, which includes iterators themselves.

§Panics

Panics if the count exceeds the capacity of the count type (T).

§Examples

Basic usage:

let arr = [1, 2, 3];
let count: usize = step_count(arr);
assert_eq!(count, 3);

Overflow:

let arr = [(); u8::MAX as usize + 1];
step_count::<u8>(arr);