Function step_count::step_count_from
source · pub fn step_count_from<T: Step>(iter: impl IntoIterator, start: T) -> T
Expand description
Consumes the iterator, counting the number of iterations,
starting from a given value.
This uses the Step
trait to keep track of the count of iterations.
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: u16 = step_count_from(arr, 2);
assert_eq!(count, 5);
Overflow:
ⓘ
let arr = [(); u8::MAX as usize - 1];
step_count_from::<u8>(arr, 2);